Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between "\n" and Environment.NewLine

What is the difference between two, if any (with respect to .Net)?

like image 818
Prerak K Avatar asked Jun 18 '09 23:06

Prerak K


People also ask

What is environment NewLine?

The Enviornment. NewLine in C# is used to add newline. To set a new line in between words − str = "This is demo text!" + Environment.NewLine + "This is demo text on next line!"; The following is the code −

Should I use environment NewLine?

Note that when writing to the console, Environment. NewLine is not strictly necessary. The console stream will translate "\n" to the appropriate new-line sequence, if necessary. The Mac implementation does exist.

What does \n do in Windows?

'\n' is the Line Feed character. Traditionally, it caused the printer to roll the paper up one line. '\r' is the Carriage Return character, which traditionally caused the printer head to move to the far left edge of the paper.

What \n means in C#?

"\n" is just a line feed (Unicode U+000A). This is typically the Unix line separator. "\r\n" is a carriage return (Unicode U+000D) followed by a line feed (Unicode U+000A). This is typically the Windows line separator.


1 Answers

Depends on the platform. On Windows it is actually "\r\n".

From MSDN:

A string containing "\r\n" for non-Unix platforms, or a string containing "\n" for Unix platforms.

like image 75
anthony Avatar answered Sep 20 '22 08:09

anthony