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 meaning we don’t need to modify it later.
StringBuilder is efficient when we deals with dynamic or larger size of string meaning we want to modify that string later on.
String is immutable. The immutable in this context means you can't modify it after it is created. It creates a new object of string type in memory if you will perform any operation.
It belongs to the System.String Namespace. It is also known as sequential collection of Unicode characters that represents text.
Dim strEx As String = "Welcome" 'creates a new string instance
strEx += "To"
strEx += "Emmason Community”
Dim res As String = strEx
C#.Net
string strEx = "Welcome"; //creates a new string instance
strEx += "To";
strEx += "Emmason Community";
string res = strEx;
StringBuilder is mutable. This means that if an operation is performed on the string, it will not create a new instance every time. With that, it will not create new space in memory, unlike Strings.
A StringBuilder belongs to the System.Text.StringBuilder Namespace/class. It represents a mutable string of characters. This class cannot be inherited.
Dim strEx As StringBuilder = new StringBuilder("")
strEx.Append("Welcome")
strEx.Append("To")
strEx.Append("Emmason Community")
Dim res As String = strEx.ToString();
StringBuilder strEx = new StringBuilder("");
strEx.Append("Welcome");
strEx.Append("To");
strEx.Append("Emmason Community");
string res = strEx.ToString();