Difference between string class & stringbuilder class in c#
Can any one please explain Difference between string class and stringbuilder class in c#
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Ezhil arasanPosted Jan 30, 2015, 5:02 AM
Manish Kumar ChoudharyPosted Jan 30, 2015, 4:27 AM
Main Differences between String and StringBuilder
String
StringBuilder
String is immutable, meaning that once you created string object then you can't modify it
StringBuilder is mutable, meaning that once you created string builder object then you can modify or append without creating a new instance for every time
Any operation that appears to change the string, it creates a new instance of string type in memory
Any operation that appears to modify or append new string, it doesn't create a new instance of string type in memory
Required Class is System.String
Required Class is System.Text.StringBuilder
Required Namespace is System
Required Namespace is System.Text
String is slower as compare to string builder object when we deals with large size of strings
StringBuilder is faster as compare to string object when we deals with large size of strings
String is efficient when we deals with static or smaller size of string means we don't need to modify later on
StringBuilder is efficient when we deals with dynamic or larger size of string means we want to modify that string later on