Open In App

Program to Print a New Line in C#

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

Examples:



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

Below is the implementation of the above approach:

Example 1:




// 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");
              
        }
    }
}

Output:



Geeksfor
Geeks
Geeks
 ForGeeks

Example 2:




// 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();
        }
    }
}

Output:

Print a new line

Save
World
Stay
Safe

Article Tags :