rspec/rules/S1643/csharp/rule.adoc

23 lines
466 B
Plaintext
Raw Normal View History

2020-12-23 14:59:06 +01:00
``StringBuilder`` is more efficient than string concatenation, especially when the operator is repeated over and over as in loops.
2020-06-30 12:47:33 +02:00
== Noncompliant Code Example
----
string str = "";
for (int i = 0; i < arrayOfStrings.Length ; ++i)
{
str = str + arrayOfStrings[i];
}
----
== Compliant Solution
----
StringBuilder bld = new StringBuilder();
for (int i = 0; i < arrayOfStrings.Length; ++i)
{
bld.Append(arrayOfStrings[i]);
}
string str = bld.ToString();
----