Environment.NewLine

Here a public response to a question that today I have received.

On a piece of code of a C# DLL I wrote for a customer, there's a piece of code where an email message is composed. The code is something like this:

sMessage="This is my mail message"+Environment.NewLine+"....."

Now the question is: why the usage of Environment.NewLine instead of a simple \n?

The answer is that on programs that must be portable to different environments, using Environment.NewLine is the best choice, because this instruction gets not a simple \n character but it gets the newline string defined for the environment where you're on. Seems a bit strange but newline is not always the same (for example on Windows platforms it's \r\n while on Unix platforms it's simply \n).

A little curiosity to improve portability...

Print | posted on Thursday, April 06, 2006 3:35 PM

Comments on this post

No comments posted yet.

Your comment:

 (will show your gravatar)
 
Please add 7 and 2 and type the answer here: