From the course: Learning C#
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Using StringBuilder - C# Tutorial
From the course: Learning C#
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.…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.