Here i will make a case for what’s difference between string and stringbuilder in c# mistreatment asp.net.
String is immutable. immutable means that once we have a tendency to produce string object we tend to cannot modify. Any operation like insert, replace or append happened to vary string merely it’ll discard the recent value and it’ll produce new instance in memory to carry the new worth..
string strNmae = "Pawan"; // create a new string instance instead of changing the old one str += "Kumar"; str += "Shukla";
String builder is mutable it means that once we tend to produce string builder object we can perform any operation like insert, replace or append without making new instance for every time.
StringBuilder sb = new StringBuilder(“”);
string strFullName = sb.ToString();
- It’s an immutable
- It’s mutable
- Performance wise string is slow because every time it will create new instance
- Performance wise stringbuilder is high because it will use same instance of object to perform any action
- In string we don’t have append keyword
- In StringBuilder we can use append keyword
- String belongs to System namespace
- Stringbuilder belongs to System.Text namespace