I understand the difference between String
and StringBuilder
(StringBuilder
being mutable) but is there a large performance difference
Yes, StringBuilder
gives better performance while performing repeated operation over a string. It is because all the changes are made to a single instance so it can save a lot of time instead of creating a new instance like String
.
String
System
namespaceStringBuilder
(mutable string)
System.Text
namespaceStrongly recommend dotnet mob article : String Vs StringBuilder in C#.
Related Stack Overflow question: Mutability of string when string doesn't change in C#?.