String is a reference type.
An object is immutable if its state doesn’t change once the object has been created. Consequently, a class is immutable if its instances are immutable.
There is one famous immutable class: System.String. When you think that you are modifying a string, you actually create a new string object.
Doing so comes at the cost of creating multiple string objects in memory when doing some intensive string computation. In this case you need to use the System.Text.StringBuilder class that provides a safe way to work with mutable string.
No comments:
Post a Comment