>>>I'd insert "in a loop" after strings, as they did some optimizatons for concatenating in a line and probably in directly following lines.
>>
>>As to 'and probably in directly following lines' I don't think so
>
>I've seen lines like
var stringres;
>stringres = str1 + str2 + str3;
>being described as special case where string concatenation is optimised.
Yes, I remember looking at that some time ago and I posted the results here
Up the 4 args and you get a call tho String.Concat( 2 to 4 args overload)
More than 4 - an array of string[] is created putting each arg into the array
Then String.Concat( string[] ) gets called
http://msdn.microsoft.com/en-us/library/System.String.Concat.aspx>I'd expect
var stringres;
>stringres = "";
>stringres = stringres + str1;
>stringres = stringres + str2;
>stringres = stringres + str3;
>to be rewritten to form 1 by an optimizing compiler as such code can be found - if they can inline whole functions, inlining concats
should be easy
No, I had checked before replying
Ildasm shows three calls to String.Concat(string, string)
Gregory