开发者

string concat in c#?

开发者 https://www.devze.com 2023-01-11 22:25 出处:网络
what is different between string +, 开发者_开发技巧string.concat(); i mean string a=\"sasi\", string b=\"surya\";

what is different between string +, 开发者_开发技巧string.concat();

i mean

string a="sasi", string b="surya";

string x= a+b, and string x= string.concat(a,b);


In that case, nothing, really. However, string.Concat() can also be used to:

  • Concatenate an array of strings (string.Concat(string[]))
  • Concatenate the string representations of an array of objects (string.Concat(object[]))
  • Concatenate an IEnumerable<T> of strings

See here for the full overload list.


There is no difference. The plus (+) operator compiles to a string.concat method; see here and here.

Newer versions of the compiler optimize the usage of the (+) operator anyways, so they are equally efficient.


If you want to see a performance benchmark check this post from Jeff


Concat performs 1 concatination regardless of how many strings are provided so has better performance over the + operaton. http://www.interact-sw.co.uk/iangblog/2004/03/16/concatperf

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号