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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Ajitender VijayPosted Jan 19, 2012, 12:38 AM
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.
Jignesh TrivediPosted Jan 17, 2012, 10:54 PM
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.
Satyapriya NayakPosted Jan 17, 2012, 10:26 PM
Please refer the below link
http://www.c-sharpcorner.com/uploadfile/jitendra1987/string-and-stringbuilder-classes/
Thanks
VulpesPosted Jan 17, 2012, 5:39 PM