StringBuilder.Append Vs StringBuilder.AppendFormat

前端 未结 9 1476
轮回少年
轮回少年 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条回答
  •  Happy的楠姐
    2021-01-31 16:20

    Append will be faster in most cases because there are many overloads to that method that allow the compiler to call the correct method. Since you are using Strings the StringBuilder can use the String overload for Append.

    AppendFormat takes a String and then an Object[] which means that the format will have to be parsed and each Object in the array will have to be ToString'd before it can be added to the StringBuilder's internal array.

    Note: To casperOne's point - it is difficult to give an exact answer without more data.

提交回复
热议问题