What are differences between system.stringbuilder and system.string?
Meenakshi Pillay
1) String are fixed length where stringbuilder is just like variable length. At the time of declaration the given length is called limitation which is String. At the run-time increasing the size is called capacity which is StringBuilder.
The main difference is system.string is immutable and system.stringbuilder is a mutable. Usage of String Builder is more efficient in case large amounts of string manipulations. Performance wise string is slow because every time it will create new instance.
system.string is immutable and we can,t change the size of string object while system.stringbuilder is mutable and we can change the size of stringbuilder class object.
http://www.aspdotnet-suresh.com/2013/11/difference-between-string-and-stringbuilder-csharp.html
System.string is immutable .ie it means when we do any operations on string object new object is created. system. String builder is mutable ,ie we can do various operations on the string, no new string object is created.
The best example for understand to stringbulider and string :for String : string s = string.Empty; for (i = 0; i < 10; i ) {s = i.ToString() " "; }for stringbuilder : StringBuilder sb = new StringBuilder(); for (i = 0; i < 10; i ) {sb.Append(i);sb.Append(' '); }
Both String and String Builder are classes used to handle strings.string is concatenation can performed very efficiently.when concatenation is done it creats a new copy in the memory as a string object, and then the old string is deleted. This process is a little long. Hence we say "Strings are immutable". When we make use of the "String Builder" object, the Append method is used. This means, an insertion is done on the existing string. Operation on String Builder object is faster than String operations, as it is done at same location. Usage of String Builder is more efficient in case large amounts of string manipulations.
System.String is immutable.Immutable means once we create string object we cannot modify Where as System.StringBuilder is mutablePerformance wise string is slow because every time it will create new instance