String The 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 a new instance in memory to hold the new value. String belongs to System namespace
=>Example string str = “hi”; //It creates a new string instance instead of changing the old one str += “help”; str += “test”;
StringBuilder String builder is mutable. Mutable means once we create string builder object we can perform any operation like insert, replace or append without creating new instance for every time. StringBuilder belongs to System.Text namespace
=> Example StringBuilder sb = new StringBuilder(“”); //It does not creats new instance for every time. sb.Append(“hi”); sb.Append(“help “); string str = sb.ToString();
String
The 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 a new instance in memory to hold the new value.
String belongs to System namespace
=>Example
string str = “hi”;
//It creates a new string instance instead of changing the old one
str += “help”;
str += “test”;
StringBuilder
String builder is mutable. Mutable means once we create string builder object we can perform any operation like insert, replace or append without creating new instance for every time.
StringBuilder belongs to System.Text namespace
=> Example
need an explanation for this answer? contact us directly to get an explanation for this answerStringBuilder sb = new StringBuilder(“”);
//It does not creats new instance for every time.
sb.Append(“hi”);
sb.Append(“help “);
string str = sb.ToString();