Two different “strings” are the same object instance?

Literal string objects are coalesced into single instances by the compiler. This is actually required by the specification:

Each string literal does not necessarily result in a new string instance. When two or more string literals that are equivalent according to the string equality operator (Section 7.9.7) appear in the same assembly, these string literals refer to the same string instance.

Leave a Comment