What is a StringBuilder?

When a string’s value is changed, a new string object is created in memory. This is because a string is immutable (it can’t be changed once created). This uses additional system resources. A StringBuilder is a mutable string-like object whose value changes based on the sequence of characters (a new string object in memory isn’t created when appended).

To use a StringBuilder, include the using statement:

using System.Text;

Instantiate a StringBuilder

In the example below, an object of StringBuilder is created.

Get hands-on with 1200+ tech skills courses.