Hi Friends
Difference between System.String and System.Text.StringBuilder classes?
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Jan 17, 2012, 12:39 PM EST
Satyapriya NayakRank #47 · 31.5K reputationPosted Jan 17, 2012, 5:26 PM EST
Please refer the below link
http://www.c-sharpcorner.com/uploadfile/jitendra1987/string-and-stringbuilder-classes/
Thanks
Jignesh TrivediRank #16 · 50.3K reputationPosted Jan 17, 2012, 5:54 PM EST
System.String is immutable. System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.
The String object is immutable which means,every time you use any of the methods in the String class, you create a new string object in memory.The StringBuilder class can be used when you want to modify a string without creating a new object.
String will allocate only what is needed. When we concatinate strings, it sums up the length of all and creates buffer to fit that.Whereas string builder allocates capacity of 16 initially and increases capacity in the multiples of 2.
Also referhttp://pranayamr.blogspot.com/2011/02/why-to-user-stringbuilder-over-string.html
hope this help.
Ajitender VijayRank #6,843 · 255 reputationPosted Jan 18, 2012, 7:38 PM EST
The String object is immutable. Every time you use one of the methods in the System.String class, you create a new string object in memory, which requires a new allocation of space for that new object. In situations where you need to perform repeated modifications to a string, the overhead associated with creating a new String object can be costly. The System.Text.StringBuilder class can be used when you want to modify a string without creating a new object. For example, using the StringBuilder class can boost performance when concatenating many strings together in a loop.
You can create a new instance of the StringBuilder class by initializing your variable with one of the overloaded constructor methods, as illustrated in the following example.