StringBuilder.Append Vs StringBuilder.AppendFormat

前端 未结 9 1456
轮回少年
轮回少年 2021-01-31 15:30

I was wondering about StringBuilder and I\'ve got a question that I was hoping the community would be able to explain.

Let\'s just forget about code readability, which o

9条回答
  •  自闭症患者
    2021-01-31 16:10

    StringBuilder also has cascaded appends: Append() returns the StringBuilder itself, so you can write your code like this:

    StringBuilder sb = new StringBuilder();
    sb.Append(string1)
      .Append("----")
      .Append(string2);
    

    Clean, and it generates less IL-code (although that's really a micro-optimization).

提交回复
热议问题