What is the difference between Write() and WriteLine() methods in C#?


The difference between Write() and WriteLine() method is based on new line character.

Write() method displays the output but do not provide a new line character.

WriteLine() method displays the output and also provides a new line character it the end of the string, This would set a new line for the next output.

Let us see an example to learn about the difference between Write() and WriteLine() method −

Example

 Live Demo

using System;
class Program {
   static void Main() {
      Console.Write("One");
      Console.Write("Two");

      // this will set a new line for the next output
      Console.WriteLine("Three");
      Console.WriteLine("Four");
   }
}

Output

OneTwoThree
Four

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 22-Jun-2020

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements