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 a c sharp?

641


what are the differences between a class and structure

748


When was .net linq added?

716


What is razor view in c#?

627


Is datetime value type c#?

626


Why do we use yield in c#?

661


What is a multi line comment?

732


Why References are stored on heap and variables on stack?

696


List down the reason behind the usage of c# language.

868


What is use of private class in c#?

721


What is a type c#?

653


What is the c# equivalent of c++ catch (...), Which was a catch-all statement for any possible exception?

725


What is the default value of object in c#?

648


What does type safety mean?

804


What tool we have to use to install assembli in gac folder.

680