Mutability of string when string doesn't change in C#
问题 If the string operation doesn't change the value of string, will that end up in creation of a new instance? For example, string str = "foo"; str += ""; I know the difference between string and StringBuilder in C#. 回答1: No, a new instance will be created only when the string operation changes the value in the string variable. It can be proved using the ObjectIDGenerator class. It's worth reading this complete article for proof. using System; using System.Text; using System.Runtime