This is a reference type but simulating
value semantic
in all aspects. For example, when you compare two referentially different strings, comparison (
==
) can be true — they are compared by the content. However, this is easy part: you can implement your own identity rules overriding System.Object.Equals, System.Object.GetHashCode (required) and optionally define custom operators "
==
" and "
!=
".
You can understand the essence of working with string references if you look at the properties
system.String.Intern
and
system.String.IsInterned
:
http://msdn.microsoft.com/en-us/library/system.string.intern.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.string.isinterned.aspx[
^].
One important practical issue with the strings: they are immutable (in contrast to mutable arrays). Therefore, for performance reasons one should never use "+" in cycles. For this (and many other) purposes, use
System.Text.StringBuilder
.
—SA