Description:-
In this article I will explain difference between String and StringBuilder in C#.
String:-
String is immutable (Unchangeable). Immutable means once we create a String object we cannot modify it. Any operation like insert, append and replace to change string it will discard the old value and it will create a new instance in the memory to hold the new value.
StringBulider:-
StringBuilder is mutable (Changeable). It means once we create StringBuilder object we can perform any operation like insert, append, and replace without creating new instance for every time.
Differences:-
1. Performance wise String is slower than StringBuilder because every time string will create new instance.
2. String belongs to System namespace whereas StringBuilder belongs to System.Text namespace.
No comments:
Post a Comment