Why strings behave like ValueType

后端 未结 7 2007
感动是毒
感动是毒 2020-12-16 23:44

I was perplexed after executing this piece of code, where strings seems to behave as if they are value types. I am wondering whether the assignment operator is operating on

7条回答
  •  悲哀的现实
    2020-12-17 00:20

    If I remember correctly once Erik Lippert wrote on SO that this behavior was chosen so that multihreading is easier and more secure. This way when you store a string in a1, you know that only you can change it. It cannot be changed from other threads for example.

提交回复
热议问题