string concat in c#?
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
精彩评论