Why is String.Concat not optimized to StringBuilder.Append? — Today I posted a tweet complaining about the lack of usage of .NET's StringBuilder class when concatenating strings. Mirko replied that the Java compiler optimizes string concatenations using StringBuilder (or StringBuffer, as mentioned in the Java Language Specification). I got curious and so I tried to figure out if the .NET compiler optimizes string concatenations using StringBuilder, too. And so I stumbled upon the linked answer. As the original poster of the answer mentions it, the real answer to this question is the compiler team's secret. Maybe I'll write a mail to the guys of the C# FAQ regarding this.

Write a Comment