| layout | page |
|---|---|
| title | CC0039 |
| tagline | StringBuilderInLoopAnalyzer |
|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.
{% highlight csharp %} var values = ""; foreach (var item in Enum.GetValues(typeof(LoaderOptimization))) { values += item.ToString(); } {% endhighlight %}
A code fix will be presented to you that will transform the code, it will use StringBuilder to concatenate the string.
{% highlight csharp %} var values = ""; var builder = new StringBuilder(); builder.Append(values); foreach (var item in Enum.GetValues(typeof(LoaderOptimization))) { builder.Append(item.ToString()); } values = builder.ToString(); {% endhighlight %}

TBD
TBD