Difference between Console.Write and Console.WriteLine in C#
Last Updated :
26 May, 2020
In C#, to print the data on the console output screen the following method are used – Console.Write() and Console.WriteLine() method. Console is a predefined class of System namespace. While Write() and WriteLine() both are the Console Class methods.
The only difference between the Write() and WriteLine() is that Console.Write is used to print data without printing the new line, while Console.WriteLine is used to print data along with printing the new line.
Program 1: Example of Console.Write() in C#.
C#
using System;
public class GFG{
static void Main( string [] args)
{
Console.Write( "Geeks" );
Console.Write( "For" );
Console.Write( "Geeks" );
}
}
|
Output:
GeeksForGeeks
Program 2: Example of Console.WriteLine() in C#.
C#
using System;
public class GFG{
static void Main( string [] args)
{
Console.WriteLine( "Geeks" );
Console.WriteLine( "For" );
Console.WriteLine( "Geeks" );
}
}
|
Output:
Geeks
For
Geeks
In the above code, program 1 shows the output without including the newline in the each console output and program 2 shows the output including the newline in the each console output.
Share your thoughts in the comments
Please Login to comment...