3 different ways in C# to print a new line

How to print a new line in C#:

We have different ways to print a new line in c#. Similar to any other programming language, a new-line character \n can be used anywhere in a string. It is translated to a newline. Similarly, we can also use the ASCII value of \n or Console.WriteLine which adds a new-line to the end of the string. If we don’t pass a string, it simply prints a new-line.

3 ways to print a new line in C#:

So, following are the three ways to print a new-line in C#:

  • Use \n
  • Use ASCII value of \n i.e. \x0A
  • Console.WriteLine()

C# Example program:

Let’s take a look at the below program:

using System;

public class Program
{
	public static void Main()
	{
		Console.WriteLine("code\nVS\ncolor");
        Console.WriteLine("code \x0A VS \x0A color");
        Console.WriteLine();

        Console.WriteLine("***end***");
	}
}

It will print the below output:

code
VS
color
code 
 VS 
 color

***end***

As you can see here, it added new lines in between the strings.