Program to Print a New Line in C#

There are various method to print a new line within the message

  • By using: \n – It prints new line.
  • By using: \x0A or \xA (ASCII literal of \n) – It prints new line.
  • By using: Console.WriteLine() – It prints new line.

Examples:

Input  : GeeksForGeeks
Output : Geeksfor
         Geeks
        
Input : Save World
Output: Save
        World

Below is the implementation of the above approach:

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to print a new line
using System;
using System.IO;
using System.Text;
  
namespace geeks
{
    class GFG
    {
        // Main Method 
        static void Main(string[] args)
        {
            // by using \n
            Console.WriteLine("Geeksfor\nGeeks");
              
            // by using \x0A
            Console.WriteLine("Geeks\x0A ForGeeks");
              
        }
    }
}

chevron_right


Output:

Geeksfor
Geeks
Geeks
 ForGeeks

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to print a new line
using System;
using System.IO;
using System.Text;
   
namespace geeks
{
    class GFG
    {
        // Main Method 
        static void Main(string[] args)
        {
               
            Console.WriteLine("Print a new line");
              
            // print only next line
            Console.WriteLine();
              
            // by using \n
            Console.WriteLine("Save\nWorld");
              
            // by using \x0A
            Console.WriteLine("Stay\x0ASafe");
               
   
            // ENTER to exit the program
            Console.ReadLine();
        }
    }
}

chevron_right


Output:

Print a new line

Save
World
Stay
Safe



My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.