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

Can u list some style properties of List Box?

730


Explain About .NET Framework

710


How do I open the console?

802


What is cookies in c# asp net?

716


How can I process command-line arguments?

745


What is regex replace in c#?

744


What is class and object c#?

697


What is different between Boxing and Unboxing?

819


How do I declare inout arguments in c#?

758


What is use of singleton class in c#?

730


What are the different types of literals in c#?

768


What are generic types?

731


What is extension method in c sharp?

705


Differentiate between object pooling and connection pooling in c#?

789


What are the different types of constructors?

748