String and StringBuilder
What is the difference between String and StringBuilder .... ??
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.
Raja TPosted Aug 20, 2015, 5:18 AM
Differences between String and StringBuilder:
It belongs to String namespace
It belongs to String. Text namespace
String object is immutable
StringBuilder object is mutable
Assigning:
String s= "something important";
Assigning:
StringBuilder sbuild= new StringBuilder("something important");
We can use '+' operator or Concat method to concatenate the strings.
Here we are using Append method.
When string concatenation happens, additional memory will be allocated.
Here additional memory will be allocated when the string buffer capacity exceeds only.
Raja TPosted Aug 20, 2015, 9:20 AM
Rajeesh MenothPosted Aug 20, 2015, 6:26 AM
Hemlata KushwahaPosted Aug 20, 2015, 6:23 AM
Hemlata KushwahaPosted Aug 20, 2015, 6:22 AM
Upendra Pratap ShahiPosted Aug 20, 2015, 6:11 AM
String is immutable, Immutable means if you create string object then you cannot modify it and It always create new object of string type in memory.
Example
string strMyValue = "Hello Visitor";
// create a new string instance instead of changing the old one
strMyValue += "How Are";
strMyValue += "You ??";
Stringbuilder
StringBuilder is mutable, means if create string builder object then you can perform any operation like insert, replace or append without creating new instance for every time.it will update string at one place in memory doesnt create new space in memory.
Example
StringBuilder sbMyValue = new StringBuilder("");
sbMyValue.Append("Hello Visitor");
sbMyValue.Append("How Are You ??");
string strMyValue = sbMyValue.ToString();
Raja TPosted Aug 20, 2015, 5:21 AM
Strings in C# .NET