What is the Main difference between String and
StringBuilder and why do we use StringBuilder.

Answer Posted / vijay rana

String class is immutable, means we can not change the
contents of string at run time,
for example
String s1="loin";
string s2=s1.insert(3,"g");
now s2 have the value login ,but one thing to notice here is
that we are not assigning this value into s1, because it is
not possible in String class
,but if we want to change the contents of s1 then we will
have to take the StringBuilder calss
because with the help of this class we can change the
contents of same string
examlpe:
String s1="loin";
s1=s1.insert(3,"g");
now s1 is "login"
here we are assigning the value again in s1,
this is the main difference between in string and
stringBuilder class

Is This Answer Correct ?    43 Yes 27 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is reference c#?

572


Why array is faster than arraylist in c#?

495


Are c# generics the same as c++ templates?

508


Explain deadlock?

523


Explain About delegates

605






Can a struct have a default constructor (a constructor without parameters) or a destructor in c#?

527


Why reflection is used in c#?

500


What is xml serialization and deserialization in c#?

488


What is icomparable in c#?

533


What is the difference between string and stringbuilder in c#?

479


What is generic collection in c#?

508


What is c# windows form application?

504


What are virtual classes in c#?

539


Explain anonymous type in c#?

530


What do you mean by jagged array?

506