You would actually both be wrong then.
The line:
TextBox1.Text = "Line1" + System.Environment.NewLine + "Line2";
Compiles to:
TextBox1.Text = string.Concat("Line 1", Environment.NewLine, "Line 2");
There is no difference in what they actually do. The only reasons would
be for semantic/aesthetic reasons.
The last one:
TextBox.Text = string.Format("Line 1{0}Line 2", Environment.NewLine);
Is actually slower, since the code has to parse the string in order to
find the tokens.
Of course, this is assuming that you know what is being concatenated.
If you were iterating through a loop of items, and you didn't know what you
were concatenating, then StringBuilder is your best bet.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"Q. John Chen" <qj****@email.com> wrote in message
news:11*********************@m73g2000cwd.googlegro ups.com...
Agree.
Dave Sexton wrote: Just FYI,
Don't do:
TextBox1.Text = "Line1" + System.Environment.NewLine + "Line2";
Do:
TextBox1.Text = string.Concat("Line 1", Environment.NewLine, "Line 2");
or
TextBox.Text = string.Format("Line 1{0}Line 2", Environment.NewLine);
"Q. John Chen" <qj****@email.com> wrote in message
news:11**********************@b68g2000cwa.googlegr oups.com... > In Windows, there should be a CR (Carrage Return) and an LF (Line
> Feed). So, do the following:
>
> TextBox1.Text = "Line 1\r\nLine 2";
>
> or
>
> TextBox1.Text = "Line1" + System.Environment.NewLine + "Line2";
>
>
> John
>