C#: Strings with same contents

后端 未结 4 1978
野性不改
野性不改 2020-12-05 11:05

I have heard and read that a string can not be changed (immutable?). That should be correct I guess. But I have also heard that two strings with the same contents share the

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-05 11:36

    This is more or less true. It is called "string interning". String literals will be present in memory only once and every variable set to the same value points to this single representation. Strings that are created in code are not automatically interned though.

    http://msmvps.com/blogs/manoj/archive/2004/01/09/1549.aspx

提交回复
热议问题