Tech moves fast! Stay ahead of the curve with Techopedia!
Join nearly 200,000 subscribers who receive actionable tech insights from Techopedia.
String, in the context of .NET, is a class representing a read-only text containing Unicode characters, which can be used to manipulate its contents. The String class is used for related operations such as concatenation, search, comparison, sorting, formatting, copying and displaying text. Strings also aid the development of globalized and localized applications by providing options for applying culture-sensitive (specific or current culture) conventions for string operations wherever applicable. For example, strings used internally have to be handled in a common way, while user-specific data such as file names, XML tags, etc. need to be culture-sensitive.
String in the .NET Framework considers Null as a character in the string, which results in the string operations (such as comparison, length, copy, etc.) executed in the .NET environment, but not in the same way as execution in native C/++ code. Selection of the appropriate string manipulation method, which is done from the set of overloads of this class to suit the requirement of application, is vital while using this class.
The contents of text stored in a String object are immutable, which implies that its value cannot be changed after its creation. In case of string manipulation functions such as string concatenation, a new string object is created and used to pass it as a return value. Unlike the String class, StringBuilder class is mutable and used in string manipulation operations without penalty on performance.
The following are best practices while using String class: