Most efficient way to concatenate strings?

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

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

17条回答
  •  离开以前
    2020-11-22 03:57

    The most efficient is to use StringBuilder, like so:

    StringBuilder sb = new StringBuilder();
    sb.Append("string1");
    sb.Append("string2");
    ...etc...
    String strResult = sb.ToString();
    

    @jonezy: String.Concat is fine if you have a couple of small things. But if you're concatenating megabytes of data, your program will likely tank.

提交回复
热议问题