C# StringBuilder

  • Blogger writing is not easy, kids need your encouragement
  • Thousands of waters and thousands of mountains are always in love, so please click a like first.

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.

  • About the blogger:
  • Industrial automation upper computer software engineer, machine vision algorithm engineer, motion control algorithm engineer. Currently working in the intelligent manufacturing automation industry. Blogger's mailbox: [email protected]
  • Help me like it. Haha.

Guess you like

Origin blog.csdn.net/cashmood/article/details/109183993