Difference between string and stringbuilder?

Answers were Sorted based on User's Feedback



Difference between string and stringbuilder?..

Answer / dsr

string is immutable.String and StringBuffer both are
classes.stringbuffer is mutable.

Is This Answer Correct ?    12 Yes 2 No

Difference between string and stringbuilder?..

Answer / akash

using String
if u want to append the text then u prefer's this thing
string strTemp="a";
strTemp=strTemp+"jay";

But in case of StringBuilder
if u want to do the samething then u will get a append() function.

Is This Answer Correct ?    6 Yes 3 No

Difference between string and stringbuilder?..

Answer / 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

More C Sharp Interview Questions

i want the csharp questions&answeres

0 Answers   IBM, Siemens,


What is ildasm and obfuscator in net?

0 Answers  


Explain how to add controls dynamically to the form using c#.net.

0 Answers  


What is array formula?

0 Answers  


Can we inherit static class in c#?

0 Answers  


What can be done with c#?

0 Answers  


Can list contain duplicates c#?

0 Answers  


Why do we need generics in c#?

0 Answers  


Define an escape sequence, name few strings in escape sequence?

0 Answers  


Why are dynamic link library used over static one?

0 Answers   C DAC,


Is arraylist thread safe?

0 Answers  


What is a byte in c#?

0 Answers  


Categories