Essential C# Immutability  Suggest an edit

System.String class

In C# (and .NET) a string is represented by class System.String. The string keyword is an alias for this class.

The System.String class is immutable, i.e once created its state cannot be altered.

So all the operations you perform on a string like Substring, Remove, Replace, concatenation using + operator etc will create a new string and return it.

See the following program for demonstration -

string str = "mystring";
string newString = str.Substring(3);
Console.WriteLine(newString);
Console.WriteLine(str);

This will print string and mystring respectively.


Table Of Contents
22 Enum
25 GUID
104 Immutability
107 Stream
108 Timers
  ↑ ↓ to navigate     ↵ to select     Esc to close