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

Answer Posted / anandha kumar t

Both String and StringBuilder are classes used to
handle the strings.

The most common operation with a string is
concatenation. This activity has to be performed very
efficiently. When we use the "String" object to concatenate
two strings, the first string is combined to the other
string by creating a new copy in the memory as a string
object, and then the old string is deleted. This process is
a little long. Hence we say "Strings are immutable".

When we make use of the "StringBuilder" object, the
Append method is used. This means, an insertion is done on
the existing string. Operation on StringBuilder object is
faster than String operations, as the copy is done to the
same location. Usage of StringBuilder is more efficient in
case large amounts of string manipulations have to be performed.

Is This Answer Correct ?    81 Yes 16 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is typeof undefined?

691


what is the purpose of using statement in c#

756


Wht executescaler method is used?

732


Int map to which .net types?

778


Is there a way of specifying which block or loop to break out of when working with nested loops?

758


what is the meaning of Object lifetime in OOPS

757


What is a int in c#?

700


What does protected internal access modifier mean?

775


Is as operator in c#?

646


What is a long in c#?

679


Explain how do I get deterministic finalization in c#?

696


Is an array an object c#?

741


Are objects passed by reference in c#?

746


How can i Spawn a Thread

702


How many types of constructor are there in c#?

673