When do you use StringBuilder.AppendLine/string.Format vs. StringBuilder.AppendFormat?

前端 未结 7 711
半阙折子戏
半阙折子戏 2021-01-31 13:34

A recent question came up about using String.Format(). Part of my answer included a suggestion to use StringBuilder.AppendLine(string.Format(...)). Jon Skeet suggested this was

相关标签:
7条回答
  • 2021-01-31 14:37

    I view AppendFormat followed by AppendLine as not only more readable, but also more performant than calling AppendLine(string.Format(...)).

    The latter creates a whole new string and then appends it wholesale into the existing builder. I'm not going to go as far as saying "Why bother using StringBuilder then?" but it does seem a bit against the spirit of StringBuilder.

    0 讨论(0)
提交回复
热议问题