Skip to content

The string Type

Question

Which kind of type is string?

Short interview answer

string is a reference type. Its instances are immutable.

Detailed answer

Copying a string variable copies a reference, but no caller can mutate the string's character data. An expression that appears to change a string creates a new instance. This makes it important not to infer mutability from whether a type is a value or reference type.

Sources