|
In C#, string is a reference type. Every time you change the value of a string object, that is, modify the string corresponding to a string variable, you need to reallocate space in memory for the new string. In the case of silent writing, if you need to repeatedly modify the value of a string variable, the memory overhead will be relatively large.
Objects of the StringBuilder class can call the ToString() method to output the contents of the StringBuilder class as string characters, and call the Append() and AppendLine() methods to add content.
E.g:
StringBuilder str = new StringBuilder();
str.Append("我爱你");
str.AppendLine("中国!");
str.Append("中国,我的祖国");
Console.WriteLine(str.ToString());
Write a console program and run it yourself, and you will understand.
|
|