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:
// 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
Please Login to comment...