Home > DeveloperSection > Interviews > What’s the difference between System.Text.StringBuilder and System.String?

Posted on    October-15-2010 12:00 AM

 C# C# 
 2 Answer(s)
  2443  View(s)
Rate this:

Uttam Misra

Total Post:54

Posted on    October-29-2010 12:00 AM

StringBuilderis more efficient in the cases, where a lot of manipulation is done to thetext. Strings are immutable, so each time it’s being operated on, a newinstance is created.

Amit Singh

Total Post:565

Posted on    April-16-2011 12:00 AM

Difference between StringBuilder and string
String and StringBuilder class stores strings. But when you cannot change a String object after creating one.
eg: String name = "amit";
By saying you cannot change the name object means you cannot change the value in name object internally. When you
change the name object value to something else, a new String object is creating in memory and assign the new
Example: name = "Amit Singh";

If you are doing string concatenation StringBuilder class is far better in performance than String class.
You can use StringBuilder's Append() method to use concatenation.

Don't want to miss updates? Please click the below button!

Follow MindStick