Use StringBuilder

Replaces string concatenation operations with method calls on a local StringBuilder instance, to improve performance (working with a StringBuilder is faster than concatenating strings).

Availability

Available from the context menu or via shortcuts:

  • when the selection contains several assignment statements that are used to construct a string (each statement appends a string to the previously accumulated value).

Example

string result = s1;
result += s2;
result += s3;
Dim result As String = s1
result += s2
result += s3

Result:

StringBuilder resultBuilder = new StringBuilder(s1);
resultBuilder.Append(s2);
resultBuilder.Append(s3);
Dim lResultBuilder As StringBuilder = New StringBuilder(s1)
lResultBuilder.Append(s2)
lResultBuilder.Append(s3)

Screenshot

rsUseStringBuilderCSharp