What Does String Mean?

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.


Techopedia Explains String

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:

  1. The right overload specifying the string comparison rule (method overload with StringComparison parameter) has to be used.
  2. For culture-agnostic string matching and performance reasons, usage of method, StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase is better.
  3. For checking equality of strings, overload of String.Equals method can be used. For sorting purposes, Compare and CompareTo can be used.
  4. Overload methods need to be used without passing default values.
  5. Rather than references, the ‘==’ operator can be used to compare two String objects for checking the equality of their contents.

Related Terms

Margaret Rouse
Technology Expert

Margaret is an award-winning technical writer and teacher known for her ability to explain complex technical subjects to a non-technical business audience. Over the past twenty years, her IT definitions have been published by Que in an encyclopedia of technology terms and cited in articles by the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine, and Discovery Magazine. She joined Techopedia in 2011. Margaret's idea of a fun day is helping IT and business professionals learn to speak each other’s highly specialized languages.