Göran Andersson <(E-Mail Removed)> wrote:
> per9000 wrote:
> > I tend to prefer a use a string br = Environment.NewLine instead of
> > \n, just in case.
>
> I think that is good advice. In a Windows system Environment.NewLine
> does not contain "\n" but "\r\n".
>
> As Marc pointed out, the compiler will most probably not be able to
> concatenate the strings at compile time.
>
> However, it's questionable if string literals should even contain line
> breaks. Perhaps an array of strings is a better way to represent data
> like this, and adding the line breaks by using WriteLine to write each
> string.
It all depends on what you're doing with it. If you're writing to the
console, then yes - but if you're getting the data ready to go down a
socket, then:
a) It makes sense to use a single string and encode it once
b) You need to make sure you use the appropriate line termination for
the protocol, rather than using Environment.NewLine.
It's certainly not the case that everywhere you see \n or \r\n you
should replace it with a call to Environment.NewLine.
--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too