Escape sequence for new line in c#
In C#, the escape sequence for a new line is \n
.
Here are a few examples:
Console.WriteLine("Hello\nWorld!");
will print:Hello World!
string myString = "Hello\nWorld!";
will create a string with a new line character.
Note that \n
is the standard escape sequence for a new line in many programming languages, including C#, Java, Python, and many others.
Alternatively, you can use the Environment.NewLine
property to get the new line character specific to the current platform (e.g. \r\n
on Windows, \n
on Unix/Linux). For example:
Console.WriteLine("Hello" + Environment.NewLine + "World!");
This will print:
Hello
World!
on Windows, and:
Hello
World!
on Unix/Linux.