TypeName | StringBuilderInLoopAnalyzer |
Check Id | CC0039 |
Category | Performance |
Severity | Warning |
Do not concatenate a string on a loop. It will alocate a lot of memory. Use a StringBuilder instead. It will will require less allocation, less garbage collector work, less CPU cycles, and less overall time.
var values = "";
foreach (var item in Enum.GetValues(typeof(LoaderOptimization)))
{
values += item.ToString();
}
A code fix will be presented to you that will transform the code, it will use StringBuilder to concatenate the string.
var values = "";
var builder = new StringBuilder();
builder.Append(values);
foreach (var item in Enum.GetValues(typeof(LoaderOptimization)))
{
builder.Append(item.ToString());
}
values = builder.ToString();
TBD
TBD