The StringBuilder Class

For direct manipulation of a string, use the StringBuilder class. It's the best solution when a lot of work needs to be done to change a string. It's more efficient for manipulation operations because, unlike a String object, it doesn't incur the overhead involved in creating a new object on every method call. The StringBuilder class is a member of the System.Text namespace.

Tip

A String instantiates and returns a new object when its contents are modified. It's a good idea to consider using a StringBuilder for string modifications to avoid the overhead associated with additional instantiations of modified string objects.

Instance Methods

The StringBuilder class doesn't have static methods. All of its methods operate on ...

Get C# Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.