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

What is the difference between string and stringbuilder in c#?

479


What is ac callback?

509


What is escape sequence in c#?

599


What does dbml mean in texting?

522


What is type keyword in c#?

536






What are the 2 types of data types available in c#?

499


Do unused Namespaces in c# affect run-time performance?

528


Can we inherit singleton class in c#?

473


What is public void in c#?

516


Why we use extension methods in c#?

474


Why interface is required?

465


What is dictionary class in c#?

478


What is the C# syntax to catch any possible exception?

534


How can we set the class to be inherited, but prevent the method from being over-ridden?

488


Give 2 scenarios where static constructors can be used?

495