Most efficent way of joining strings

前端 未结 11 1724
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-18 05:51

I need to concatenate a lot of strings alltogether and put a comma between any of them. I have a list of strings

\"123123123213\"
\"1232113213213\"
\"1232131         


        
11条回答
  •  隐瞒了意图╮
    2021-01-18 06:27

    You should use string.Join() because:

    a) it's much more readable, maintainable and easy on the eyes.

    b) it uses a StringBuilder internally already, so it's very efficient ( you can confirm yourself using Reflector).

    Edit:

    string.Join() uses a StringBuilder for the general case of an IEnumerable input. If you already have an array on the other hand it uses some voodoo magic (including FastAllocateString() and UnSafeCharBuffer) to be even faster.

提交回复
热议问题