StringBuilder is used to represent a mutable string of characters. mutable means the string which can be changed. So string object are immutable but string builder is the mutable string type.
StringBuilder will not create a new modified instance of the current string object, but do the modification in the existing string objects.
String will create a new modified instance of the current string object at time of modification in the existing string objects.
//By using string String class it create object every time when we are concinnated the string
string sValue = "C#";
sValue += " Java";
sValue += " PHP";
sValue += " Python";
sValue += " C";
sValue += " C++";
Console.WriteLine(sValue);
//By for better performance here we should use the StringBuilder Class
StringBuilder stringBuilder = new StringBuilder("C#");
stringBuilder.Append("Java");
stringBuilder.Append("C");
stringBuilder.Append("C++");
stringBuilder.Append("PHP");
Console.WriteLine(stringBuilder);
No comments:
Post a Comment