Q:

C# program to print a new line

belongs to collection: C# Basic Programs | basics

0

C# printing a new line

To print a new line within the message while printing it on the console, we can use following methods,

  • Using \n – prints new line
  • Using \x0A or \xA (ASCII literal of \n) – prints new line
  • Console.WriteLine() – prints new line, if we write any message in the method – it will print new line after the message, if we do not write any message – it will print a new line only.
  •  

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

C# code to print new line

In the below example – we are printing new lines between the messages or/and after the message.

// C# program to print a new line
using System;
using System.IO;
using System.Text;

namespace IncludeHelp
{
    class Test
    {
        // Main Method 
        static void Main(string[] args)
        {
            //using \n
            Console.WriteLine("Hello\nWorld");
            //using \x0A
            Console.WriteLine("Hello\x0AWorld");
            Console.WriteLine();

            Console.WriteLine("end of the program");

            //hit ENTER to exit the program
            Console.ReadLine();
        }
    }
}

Output

Hello
World
Hello
World

end of the program

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | basics

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to print backslash (\\)... >>
<< C# program to demonstrate example of Console.Write...