Newline in C# – \r\n ?

Coming originally from a VB background I was perfectly content using vbCrLf to add newlines to my strings.  Unable to find a C# equivalent, all my early C# code was scattered with ‘\r\n’ as a suitable replacement.
 
Works well, doesn’t it?
 
Well yes, right up until the point that you run it on a non-Windows system.  Unix, for example, uses just ‘\n’ and as you can imagine this makes things look just a little bit untidy.
 
Microsoft have very helpfully provided the perfect solution:
 
Environment.NewLine
 
This handy little fella returns the newline string for the current platform.
 
For those of you who are interested the full rundown is here… Environment.NewLine

Be First to Comment

Leave a Reply