What is the difference between string class and stringbuilder class?

Showing Answers 1 - 6 of 6 Answers

hanumesh_06

  • Aug 10th, 2007
 

string class in immutable. Immutable is nothing but the value assigned to string cannot be changed.


Stringbuilder class is mutable. mutable is nothing but the value assigned to stringbuilder  can be changed.

String is immutable where as stringbuilder is mutable.

That means: The value in a string can not be modified once it has been created. When you modify a string in your code, it actually creates a new string with the modified value and the string object only starts to reference this new (modified) string. That is why, .Net has System.Text.StringBuilder class (to modify the string). So, if you need to change the value in your string heavily, you should use the StringBuilder.

But you should not use the StringBuilder everytime as it will take a toll on the performance of your application

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions