WHAT IS THE DIFFERENCE BETWEEN STRING AND STRING BUILDER ?

Answer Posted / stanly jose

String and StringBuilder class stores strings. But you
cannot change a String object after creating one.
eg: String name = "Stanly";
you wan to change the same string name to
eg: name = "Stanly Jose";
then a new String object is creating in memory and assign
the new value as "Stanly Jose".
(A new name object is creating in memory and the
value "Stanly Jose" is assinging to the newly created
space.)

But StringBuilder class occupies the same space even if you
change the value.

If you are doing string concatenation StringBuilder class
is far better in performance than String class.

You can use StringBuilder's Append() method to use
concatenation.

note:
system.string is immutable,system.stringbuilder was
designed with the purpose of having a mutable string where
a variety of operations can be performed.

Is This Answer Correct ?    14 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the c# equivalent of c++ catch (...), Which was a catch-all statement for any possible exception?

493


Explain the difference between the debug class and trace class?

492


In a single .NET DLL how many classes it contains?

512


What will be the output of the following code?

505


Is as operator in c#?

467






Can firstordefault return null?

499


Why ref is used in c#?

464


What is difference between internal and protected internal in c#?

456


What is difference between const and static in c#?

488


Is c# a keyword?

490


What is list array in c#?

468


How do I calculate relative time?

494


List some of the common data providers for ado.net framework?

452


How many types of collections are there in c#?

480


What is public or shared assemblies ?

544