String vs string

Recently i had a discussion with my collegue regarding when to use .tostring() and convert.tostring(), in the discussion we are talked about string is whether value type or reference type.After having research on the web i found that string is reference type and i found differences between String and string. Conclusions i drawn from my research on given below
Sources i refered are
http://msdn.microsoft.com/en-us/library/system.string.aspxhttp://stackoverflow.com/questions/215255/string-vs-string-in-chttp://en.csharp-online.net/CSharp_String_Theory%E2%80%94string_versus_String
http://peterkellner.net/2007/12/29/incsharpwhentousestringversesstring/http://www.htmlforums.com/archive/index.php/t-53425.html
Use "String" to refer specifically to the String class.
Use "string" when referring to an object of the String class.
from msdn i found following points for String class
A string is a sequential collection of Unicode characters that is used to represent text. A String object is a sequential collection of System..::.Char objects that represent a string. The value of the String object is the content of the sequential collection, and that value is immutable.
A String object is called immutable (read-only) because its value cannot be modified once it has been created. Methods that appear to modify a String object actually return a new String object that contains the modification. If it is necessary to modify the actual contents of a string-like object, use the System.Text..::.StringBuilder class.
Each Unicode character in a string is defined by a Unicode scalar value, also called a Unicode code point or the ordinal (numeric) value of the Unicode character. Each code point is encoded using UTF-16 encoding, and the numeric value of each element of the encoding is represented by a Char object.
A single Char object usually represents a single code point; that is, the numeric value of the Char equals the code point. However, a code point might require more than one encoded element. For example, a Unicode supplementary code point (a surrogate pair) is encoded with two Char objects.
Indexes
An index is the position of a Char object, not a Unicode character, in a String. An index is a zero-based, nonnegative number starting from the first position in the string, which is index position zero. Consecutive index values might not correspond to consecutive Unicode characters because a Unicode character might be encoded as more than one Char object. To work with each Unicode character instead of each Char object, use the System.Globalization..::.StringInfo class.
Ordinal vs. Culture-Sensitive Operations
Members of the String class perform either an ordinal or linguistic operation on a String object. An ordinal operation acts on the numeric value of each Char object. A linguistic operation acts on the value of the String taking into account culture-specific casing, sorting, formatting, and parsing rules. Linguistic operations execute in the context of an explicitly declared culture or the implicit current culture. For more information about the current culture, see the CultureInfo..::.CurrentCulture topic.
Casing rules determine how to change a Unicode character between one case and another; for example, from lowercase to uppercase.
Formatting rules determine how to convert a value to its string representation, while parsing rules determine how to convert a string representation to a value.
Sort rules determine the alphabetic order of Unicode characters and how two strings compare to each other. For example, the Compare method performs a linguistic comparison while the CompareOrdinal method performs an ordinal comparison. Consequently, if the current culture is U.S. English, the Compare method considers 'a' less than 'A' while the CompareOrdinal method considers 'a' greater than 'A'.
The .NET Framework supports word, string, and ordinal sort rules. A word sort performs a culture-sensitive comparison of strings in which certain nonalphanumeric Unicode characters might have special weights assigned to them. For example, the hyphen ("-") might have a very small weight assigned to it so that "coop" and "co-op" appear next to each other in a sorted list. A string sort is similar to a word sort, except that there are no special cases and all nonalphanumeric symbols come before all alphanumeric Unicode characters.
A culture-sensitive comparison is any comparison that explicitly or implicitly uses a CultureInfo object, including the invariant culture that is specified by the CultureInfo..::.InvariantCulture property. The current implicit culture is specified by the Thread..::.CurrentCulture property.
An ordinal sort compares strings based on the numeric value of each Char object in the string. An ordinal comparison is automatically case-sensitive because the lowercase and uppercase versions of a character have different code points. However, if case is not important in your application, you can specify an ordinal comparison that ignores case. This is equivalent to converting the string to uppercase using the invariant culture and then performing an ordinal comparison on the result.
For more information about word, string, and ordinal sort rules, see the System.Globalization..::.CompareOptions topic.
A culture-sensitive comparison is typically appropriate for sorting, whereas an ordinal comparison is not. An ordinal comparison is typically appropriate for determining whether two strings are equal (that is, for determining identity), whereas a culture-sensitive comparison is not.
The Remarks for comparison and search methods specify whether the method is case-sensitive and/or culture-sensitive. By definition, any string, including the empty string (""), compares as greater than a null reference, and two null references compare as equal to each other.
Normalization
Some Unicode characters have multiple equivalent binary representations consisting of sets of combining and/or composite Unicode characters. The Unicode standard defines a process called normalization that returns one binary representation when given any of the equivalent binary representations of a character. Normalization can be performed with several algorithms, called normalization forms, that obey different rules. The .NET Framework currently supports normalization forms C, D, KC, and KD. A pair of normalized strings is typically evaluated with an ordinal comparison.
Security Considerations
If your application makes a security decision about a symbolic identifier such as a file name or named pipe, or persisted data such as the text-based data in an XML file, the operation should use an ordinal comparison instead of a culture-sensitive comparison. This is because a culture-sensitive comparison can yield different results depending on the culture in effect, whereas an ordinal comparison depends solely on the binary value of the compared characters.
Functionality
The String class provides members to compare String objects, return the index of a character or string within a String object, copy the value of a String object, partition a string or combine strings, modify the value of string, format numbers, dates and times, or enumeration values into a string, and normalize a string.
Use the Compare, CompareOrdinal, CompareTo, Equals, EndsWith, and StartsWith methods for comparisons.
Use the IndexOf, IndexOfAny, LastIndexOf, and LastIndexOfAny methods to obtain the index of a substring or Unicode character in a string.
Use Copy and CopyTo to copy a string or substring to another string or an array of type Char.
Use the Substring and Split methods to create one or more new strings from portions of an original string, and the Concat and Join methods to create a new string from one or more substrings.
Use Insert, Replace, Remove, PadLeft, PadRight, Trim, TrimEnd, and TrimStart to modify all or part of a string.
Use the ToLower, ToLowerInvariant, ToUpper, and ToUpperInvariant methods to change the case of Unicode characters in a string.
Use Format to replace one or more format item placeholders in a string with the text representation of one or more numeric, date and time, or enumeration values.
Use the Length property to obtain the number of Char objects in a string, and the Chars property to access the actual Char objects in a string.
Use the IsNormalized method to test whether a string is normalized to a particular normalization form. Use the Normalize method to create a string that is normalized to a particular normalization form.
Strings and Embedded Nulls
In the .NET Framework, a String object can include embedded nulls, which count as a part of the string's length. However, in some languages, such as C and C++, a null character indicates the end of a string, is not considered a part of the string, and is not counted as part of the string's length. This means that the following common assumptions that C and C++ programmers or that libraries written in C or C++ might make about strings are not necessarily valid when applied to String objects:
The value returned by the strlen or wcslen functions does not necessarily equal String..::.Length.
The string created by the strcpy_s or wcscpy_s functions is not necessarily identical to the string created by the String..::.Copy method.
You should ensure that native C and C++ code that instantiates String objects, and code that is passed String objects through platform invoke, do not assume that an embedded null marks the end of the string.
Implemented Interfaces
The String class implements the IComparable, ICloneable, IConvertible, IEnumerable, and IComparable<(Of <(T>)>) interfaces. Use the Convert class for conversions instead of this type's explicit interface member implementation of IConvertible

Popular Posts