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

Answer Posted / sandeep soni

String are Immutable (Not Modifiable). If you try to modify
the string it actually creates a new string and the old
string will be then ready for garbage collection.

StringBuilder when instantiated, creates a new string with
predefined capacity and upto that capacity it can
accodomate string without needing to create a new memory
location for the string....i mean it is modifiable and can
also grow as and when needed.

When the string needs to be modified frequently, preferably
use StringBuilder as its optimized for such situations.

Is This Answer Correct ?    113 Yes 11 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a scope in c#?

482


How to use reflection to call generic method?

502


Why do canadians say zed?

525


What is the c# equivalent of c++ catch (…), which was a catch-all statement for any possible exception? Does c# support try-catch-finally blocks?

515


What is virtual class in C#?

546






What happens if you add duplicate elements to a set?

504


What is cts, clr?

437


Is array reference type in c#?

490


What's c# ?

594


What are delegates and why are they required?

512


What is the difference between values and reference types?

528


What are Namespaces?

563


What is the difference between var and dynamic types in c# 4.0?

515


Why singleton class is sealed?

484


What is delegates in c# and uses of delegates?

473