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

How to declare a property in a class?

0 Answers  


Trace the O/p for a program on inheritance and Polymorphism. 3 classes A,B,C A with two methods public virtual SomeMethodA public virtual SomemoreMethodA B:A overide virtual SomeMethodA C:B new Method SomeMethodA override SomeMoreMethodA main method { b new instance of B b.SomeMethodA b.SomeMoreMethodA b1 new instance of C b1.SomeMethodA b1.SomeMoreMethodA }

1 Answers  


What is the namespace for the thread class?

0 Answers  


What is the use of partial methods?

0 Answers  


What is private and shared assembly?

0 Answers  






Is an interface a type c#?

0 Answers  


If the original method is not static you can declare an override method to be static or not?

0 Answers   Siebel,


What is difference between ienumerable and list?

0 Answers  


What is static and use of it?

0 Answers  


3. Use layered architecture for coding. s.no name description 1 abc xxxxxxxxx 2 abc xxxxxxxxx 3 4 5 6 7 8 Select all Clear all Add Delete Name Description Save close

0 Answers  


in object oriented programming, how would you describe encapsulation?

0 Answers   Siebel Systems,


What is ac callback?

0 Answers  


Categories