Most efficient way to concatenate strings?

后端 未结 17 1274
野趣味
野趣味 2020-11-22 03:04

What\'s the most efficient way to concatenate strings?

17条回答
  •  伪装坚强ぢ
    2020-11-22 03:36

    From Chinh Do - StringBuilder is not always faster:

    Rules of Thumb

    • When concatenating three dynamic string values or less, use traditional string concatenation.

    • When concatenating more than three dynamic string values, use StringBuilder.

    • When building a big string from several string literals, use either the @ string literal or the inline + operator.

    Most of the time StringBuilder is your best bet, but there are cases as shown in that post that you should at least think about each situation.

提交回复
热议问题