Search code examples
c#newlineconsole.writeline

Best practice to write new line in C#


I would like to know which is the best way to write new line in a console application which one is cross-platform.

Which one is the best way to do it (if has any):

  • Console.WriteLine();

  • Console.WriteLine("");

  • Console.WriteLine("\n");

  • Console.WriteLine(Environment.NewLine);

I don't like the \n escape sequence when I write an empty line. I prefer the first option but I'm not sure that every program (+ IDE, compiler) will recognize it without the "" marks.


Solution

  • Console.WriteLine() will take care of the line ending for you. No need for any argument in it.