Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • 2
    Why would you do this rather than using first + Environment.NewLine + second which is more efficient and (IMO) easier to read? Commented Nov 3, 2010 at 9:51
  • @Jon: More efficient, really? I thought that String.Format will produce 1 string at once (but it's internally a bit slow because of culture specific concatenations, etc), while string concatenation - 1 resulting + 1 temporary, right? Commented Nov 3, 2010 at 9:55
  • 1
    @abatishchev: the compiler converts str+str+str to String.Concatenate, which directly builds just one output string (IIRC, if the strings are literals the concatenation is done in the compiler. Commented Nov 3, 2010 at 10:02
  • @Richard: i.e. multiple but one-line string concatenation ("a"+b+"c"+d, etc) by performance are equal to a single one? Or just converted to String.Concatenate(a,b,c,d,etc), right? Commented Nov 3, 2010 at 10:04
  • @abatishchev: That's why I didn't suggest string.Format in the comment. The string concatenation won't produce any temporary strings, because the compiler will call string.Concat(first, Environment.NewLine, second). Commented Nov 3, 2010 at 10:07