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 : w3wiki Output : Beginnerfor Beginner 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 Beginner { class GFG { // Main Method static void Main( string [] args) { // by using \n Console.WriteLine( "Beginnerfor\nBeginner" ); // by using \x0A Console.WriteLine( "Beginner\x0A ForBeginner" ); } } } |
Output:
Beginnerfor Beginner Beginner ForBeginner
Example 2:
// C# program to print a new line using System; using System.IO; using System.Text; namespace Beginner { 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