Most efficient way to concatenate strings?

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

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

17条回答
  •  余生分开走
    2020-11-22 04:00

    There are 6 types of string concatenations:

    1. Using the plus (+) symbol.
    2. Using string.Concat().
    3. Using string.Join().
    4. Using string.Format().
    5. Using string.Append().
    6. Using StringBuilder.

    In an experiment, it has been proved that string.Concat() is the best way to approach if the words are less than 1000(approximately) and if the words are more than 1000 then StringBuilder should be used.

    For more information, check this site.

    string.Join() vs string.Concat()

    The string.Concat method here is equivalent to the string.Join method invocation with an empty separator. Appending an empty string is fast, but not doing so is even faster, so the string.Concat method would be superior here.

提交回复
热议问题