Strings are not really immutable. They are just publicly immutable.
It means you cannot modify them from their public interface. But in the inside the are actually mutable.
If you don't believe me look at the String.Concat
definition using reflector.
The last lines are...
int length = str0.Length;
string dest = FastAllocateString(length + str1.Length);
FillStringChecked(dest, 0, str0);
FillStringChecked(dest, length, str1);
return dest;
As you can see the FastAllocateString
returns an empty but allocated string and then it is modified by FillStringChecked
Actually the FastAllocateString
is an extern method and the FillStringChecked
is unsafe so it uses pointers to copy the bytes.
Maybe there are better examples but this is the one I have found so far.