2
Reply

What are the differences between System.String and System.Text.StringBuilder classes?

Gautam Kumar

Gautam Kumar

Nov 19, 2013
1.7k
0

    String is immutable. Immutable means once we create string object we cannot modify. Any operation like insert, replace or append happened to change string simply it will discard the old value and it will create new instance in memory to hold the new value.Example: string str = "dev"; onestr = "endra"; str = "help"; String builder is mutable it means once we create string builder object we can perform any operation like insert, replace or append without creating new instance for every time.Example: StringBuilder sb = new StringBuilder(""); sb.Append("hi"); sb.Append("test "); string str = sb.ToString();

    Divendra Ojha
    July 17, 2014
    0

    System.String is immutable. When we modify the value of a string variable then a new memory is allocated to the new value and the previous memory allocation released. System.StringBuilder was designed to have concept of a mutable string where a variety of operations can be performed without allocation separate memory location for the modified string.

    Gautam Kumar
    November 19, 2013
    0