Difference between Console.Write and Console.WriteLine in C#

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#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to show the difference
// between Console.Write and 
// Console.WriteLine
    
using System;
  
public class GFG{
    
    static void Main(string[] args)
    {
        // use of Write() method
        Console.Write("Geeks");
        Console.Write("For");
        Console.Write("Geeks");
    }
}

chevron_right


Output:

GeeksForGeeks

Program 2: Example of Console.WriteLine() in C#.

C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to show the difference
// between Console.Write and 
// Console.WriteLine
    
using System;
  
public class GFG{
    
    static void Main(string[] args)
    {
        // use of WriteLine() method
        Console.WriteLine("Geeks");
        Console.WriteLine("For");
        Console.WriteLine("Geeks");
    }
}

chevron_right


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.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.