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

Which class does the remote object has to inherit?

608


Why is c# used?

485


What is Satellite Assemblies ?

556


What is state c#?

440


How do you create dlls in .NET

578






Which is better interface or abstract class in c#?

445


What is event and delegates in c#?

576


What is the use of console?

491


Is c# different than c++?

518


Explain the difference between Response.Write () and Response.Output.Write ().

530


Define Final Class in C#

552


What are the steps to make an assembly to public?

502


Is c# used for any core features of windows vista?

525


Why abstract class is not instantiated in c#?

526


Explain how do you directly call a native function exported from a dll?

509