Difference between string and stringbuilder?

Answer Posted / vinodh kumar

Though string looks like mutable(the value can be changed once after initial value) but string is not mutable. Every time you modify the string a new object reference will be created and it will gets updated. StringBuilder is mutable.

In situations like you want to concat strings in loopings, we'll use StringBuilder.

In loops like for, for each, while, etc., using string for concatenation it will give negative performance.

Conclusion:
-----------
String is Immutable.
StringBuilder is Mutable. For performance reasons during concatenation operations in string in conditional looping statements we use StringBuilder.
http://msdn.microsoft.com/en-us/library/system.text.stringbuilder.aspx

Is This Answer Correct ?    4 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Describe ways of cleaning up objects in c#.

512


what is difference between is and as operators in c#?

537


Does c# support try-catch-finally blocks?

480


What are Uses of CLR

534


What is difference between c sharp and c#?

470






Can you declare struct members as protected?

501


How Is The Dll Hell Problem Solved In .net?

597


What is .dbml file?

481


How do I join one form to another in c#?

466


What is Implicit conversion in C#?

565


What is ado c#?

535


In c#, what will happen if you do not explicitly provide a constructor for a class?

518


Explain the difference between “constant” and “read-only” variables used in c#?

509


How do partial classes work in c#?

484


What is arraylist class in c#?

532