String vs StringBuilder in C# - ablealias/asp.net GitHub Wiki
String
String is immutable. Immutable means once we create string object we cannot modify. Any operation like insert, replace or append happened to change string simply it will discard the old value and it will create new instance in memory to hold the new value.
- It’s an immutable
- Performance wise string is slow because every time it will create new instance
- In string we don’t have
appendkeyword - String belongs to
Systemnamespace
String Builder
String builder is mutable it means once we create string builder object we can perform any operation like insert, replace or append without creating new instance for every time.
- It’s mutable
- Performance wise stringbuilder is high because it will use same instance of object to perform any action
- In StringBuilder we can use
appendkeyword - Stringbuilder belongs to
System.Textnamespace