课程: Learning C#

今天就学习课程吧!

今天就开通帐号,24,600 门业界名师课程任您挑!

Using StringBuilder

Using StringBuilder

- [Instructor] Building strings out of other strings is another very common operation in a variety of programming scenarios and the C# StringBuilder class aims to make this both easier to accomplish and more efficient. In .NET, the string object is immutable. When you call functions that make changes to strings, what you're actually doing is you're creating a copy of the string behind the scenes, which requires allocating the memory for the new string each time. And doing this over and over again can be a drag on performance and memory usage, which you can help avoid by using the StringBuilder. So let's go ahead and open up the sample code in the Builder folder. And the StringBuilder is located in the System.Text namespace, so that's why I'm including this here. So what we're going to do is start off by creating a StringBuilder and the way that we do that is I'll just declare the variable of type StringBuilder.…

内容