-3

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.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
BushWookie
  • 51
  • 1
  • 1
  • 8
  • 1
    Mureinik is right and also, if you want to use the hotkey to write it faster in visual studio, juste write "cw" then press TAB . – Christophe Chenel Oct 20 '18 at 15:17
  • I wonder where your belief comes from that `Console.WriteLine()` wouldn't be supported by a C# compiler... –  Oct 20 '18 at 15:22
  • Why are people down voting? The persons question is well formatted and shows they also did some ”research” on their own... – G. LC Oct 20 '18 at 15:23
  • @G.LC Well if he would have done any research he would have probaply noticed that Console.WriteLine already makes a new line. – Twenty Oct 20 '18 at 15:41
  • @Christophe Gudlake Thanks, best tip! – BushWookie Oct 20 '18 at 17:21
  • @ elgonzo Once time I wrote code in another IDE and it's marked it as error (red line), that's why I added this part. – BushWookie Oct 20 '18 at 17:21
  • @G.LC & @Twenty I exactly know that it makes a new line... I just wanted to make sure that I do everything fine with the `Console.WriteLine()` when I use it. I read something about `\r\t` when I google about the new line and they wrote that the `\r` is not fit for Linux. So again, I just wanted to make sure I won't run any problem with WriteLine(). – BushWookie Oct 20 '18 at 17:21

1 Answers1

3

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

Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • Thanks Mureinik! So, can I use it safe and I will not get any compatibility problem when I run the program in an other OP system? – BushWookie Oct 20 '18 at 17:24