VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/c-sharp-string-vs-stringbuilder/

⇱ C# String vs StringBuilder - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C# String vs StringBuilder

Last Updated : 20 Apr, 2026

StringBuilder is used to represent a mutable string of characters. Mutable means the string which can be changed. So String objects are immutable but StringBuilder is the mutable string type. It will not create a new modified instance of the current string object but performs modifications on the same StringBuilder object without creating a new object.

The complete functionality of StringBuilder is provided by StringBuilder class which is present in System.Text namespace.

String vs StringBuilder

FeatureStringStringBuilder
MutabilityImmutable (cannot be changed after creation)Mutable (can be changed without creating new objects)
PerformanceSlower for frequent modificationsFaster for frequent modifications
Memory UsageCreates a new object for each modificationModifies the same object, reducing memory overhead
Use CaseUse for small or infrequently modified stringsUse for large or frequently modified strings
Modification MethodsModification requires creating a new stringModification is done in-place
Thread SafetyStrings are thread-safeStringBuilder is not inherently thread-safe

Example: Demonstrating the differences between String and StringBuilder


Output
Using String Class: Geeks
Using StringBuilder Class: GeeksforGeeks

Explanation:

  • Use of concat1 Method: In this method, we are passing a string “Geeks” and performing “s1 = String.Concat(s1, st);” where st is “forGeeks” to be concatenated. The string passed from Main() is not changed, this is due to the fact that String is immutable.
  • Use of concat2 Method: In this method, we are passing a string “Geeks” and performing “s2.Append(“forGeeks”)” which modifies the same StringBuilder object by appending new content, as it is mutable.

Converting String to StringBuilder

To convert a String class object to StringBuilder class object, just pass the string object to the StringBuilder class constructor.

Example:


Output
GeeksForGeeks

Converting StringBuilder to String

This conversions can be performed using ToString() method.

Example:


Output
StringBuilder object to String: Builder
Comment
Article Tags:
Article Tags:

Explore