Author: aresssrinivas | Posted on: 10/19/2010 3:38:18 AM | Views : 277


  String is immutable and StringBuilder is mutable. So if I change the value of a string a new memory created with the new value, whereas in StringBuilder it updates its memory location rather than creating a new memory location. So for large concatenation stringBuilders are preffered.

But  when I create a new String object, a fixed memory is created. And any changes will update its memory location, rather than creating a new memory location.

For e.g.
String s = new String();
s = String.Empty;
for ( int i=0;i<100; i++)
{
    //s = s + "test"  + i.ToString();
               s  =string.Concat(s, "test"  + i.ToString()); ///This is effecient compared to previous step
}


Now instead of String class I will use a StringBuilder class..........

StringBuilder s = new Strin ...

Go to the complete details ...