Difference between String and String Buffer in c#?

 Posted by Sathya4260 on 1/31/2011 | Category: C# Interview questions | Views: 25733 | Points: 40

1.Its a class used to handle strings.
2.Here concatenation is used to combine two strings.
3.String object is used to concatenate two strings.
4.The first string is combined to the other string by
creating a new copy in the memory as a string object, and
then the old
string is deleted
5.we say "Strings are immutable".
6.When using concatenation consumes more memory.

String Builder..
1.This is also the class used to handle strings.
2.Here Append method is used.
3.Here, Stringbuilder object is used.
4.Insertion is done on the existing string(no new memory is allocated)
5.Usage of StringBuilder is more efficient in case large
amounts of string manipulations have to be performed
6.Consumes less memory when compared to String, if we add the characters to the string in future.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response