Environment NewLine

August 3, 2006

If you are one of those people that put “\r\n” in your strings to indicate a newline, raise your right hand and smack your head.

Why?

1) You are assuming your code will always run on Windows. Unix uses \n alone, Apple (until OS 9) used \r alone. Your code might just end up being compiled under Mono and then what?
2) It looks plain ugly
3) You have to escape the characters again (at least in C# if you’re not using the verbatim operator @). This quickly becomes a pain in the — er –becomes cumbersome when dealing with a lot of text

What should you do?

Simple

string line = string.Format(“And this is the end of the line{0}”, Environment.NewLine);

kick it on DotNetKicks.com