ALERT

[WEBINAR] Building a Business-Driven Data Architecture

String

Definition - 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.
This definition was written in the context of .NET

Connect with us

Techopedia on Linkedin
Techopedia on Linkedin
Tweat cdn.techopedia.com
"Techopedia" on Twitter


'@Techopedia'
Sign up for Techopedia's Free Newsletter!

Email Newsletter

Join thousands of others with our weekly newsletter

Resources
Free Whitepaper: The Path to Hybrid Cloud
Free Whitepaper: The Path to Hybrid Cloud:
The Path to Hybrid Cloud: Intelligent Bursting To Amazon Web Services & Microsoft Azure
Free E-Book: Public Cloud Guide
Free E-Book: Public Cloud Guide:
This white paper is for leaders of Operations, Engineering, or Infrastructure teams who are creating or executing an IT roadmap.
Free Tool: Virtual Health Monitor
Free Tool: Virtual Health Monitor:
Virtual Health Monitor is a free virtualization monitoring and reporting tool for VMware, Hyper-V, RHEV, and XenServer environments.
Free 30 Day Trial – Turbonomic
Free 30 Day Trial – Turbonomic:
Turbonomic delivers an autonomic platform where virtual and cloud environments self-manage in real-time to assure application performance.