WHAT IS THE DIFFERENCE BETWEEN STRING AND STRING BUILDER ?

Answer Posted / raviraj

String and String Builder class shows resemblance in terms
of values they accept(that contain series of haracters).But
the thing that distinguishes them is that string is
immutable .Immutable in the sense it will create a new copy
of memory whenever a new string is concatenated to the
existing string variable That means the existing memory is
deleted and replaced by the new memory.Whereas
Stringbuilder is mutable whenever we append a new string to
the existing string variable using append method the memory
containing the original string is extended to contain the
new string as well i.e, it won`t replace it with new memory
allocation.Hence performing string concatenations within
the same variable in the string class variables will affect
their performance.

Is This Answer Correct ?    17 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Does c# provide copy constructor?

569


What is indexer c#?

464


What benefit do you get from using a primary interop assembly (pia)?

506


Can class inherit from struct c#?

507


Is string mutable in c#?

477






What is the difference between dynamic type variables and object type variables in c#?

481


Is string immutable in c#?

568


List out two different types of errors in c#?

523


How do I declare a pure virtual function in c#?

584


What are winforms in c#?

493


What is different between Implicit conversion and Explicit conversion in C#?

513


What is an assembly in .net?

572


Why does my windows application pop up a console window every time I run it?

518


What is boolean method?

511


What is the use of tryparse in c#?

460