The Difference between String and StringBuilder in C#

Previous: String Next: Exercise

The StringBuilder class provides the developer with a set of methods that allows manipulation of a mutable string of characters, it can be used when you want to modify a string without creating a new object, thus eliminating the overhead or bottleneck issue of the normal String concatenation.

Using the StringBuilder class can boost performance when concatenating many strings together in a loop.

To use StringBuilder class, you need to make sure you are using the namespace System.Text

The following is a list of a few operations that can be performed to manipulate a string using the StringBuilder Class in .NET

  • Append: Appends information to the end of the current StringBuilder.

  • AppendLine: Appends information as well as the default line terminator to the end of the current StringBuilder.

  • AppendFormat: Replaces a format specifier passed in a string with formatted text.

  • Insert: Inserts a string or object into the specified index of the current StringBuilder.

  • Remove: Removes a specified number of characters from the current StringBuilder.

  • Replace: Replaces a specified character at a specified index.

For the complete list of available methods in StringBuilder class, please refer to Microsoft's documentation here

Create your playground on
This playground was created on, our hands-on, knowledge-sharing platform for developers.
Go to
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
Online Participants