Why is String.Concat not optimized to StringBuilder.Append?

后端 未结 8 1204
小鲜肉
小鲜肉 2020-12-05 07:39

I found concatenations of constant string expressions are optimized by the compiler into one string.

Now with string concatenation of strings only known at run-time,

8条回答
  •  北荒
    北荒 (楼主)
    2020-12-05 07:54

    I believe it would be a little too complex for the compiler writers. And when you are referencing the intermediate strings inside the loops besides the concatenation (for example passing them to some other methods or so), this optimization would not be possible.

提交回复
热议问题