What are Console.WriteLine() and Console.Write() in C#?

Overview

The Console.WriteLine() and Console.Write() methods print values or texts to the console. The Console.WriteLine() method prints a new line after the text or a value. The Console.Write() method only prints the text or value without a new line.

Syntax

Console.WriteLine(value)
Console.Write(value)
The syntax for Console.WriteLine() and Console.Write()

Parameters

value: This can be a text or a value.

Return value

value is returned or printed to the console.

Code

An example of Console.Write()

using System;
class HelloWorld {
static void Main() {
Console.Write("Hello");
Console.Write(" and welcome ");
Console.Write("to ");
Console.Write("Edpresso!");
}
}

Explanation

  • Lines 4-7: We print some texts to the console using the Console.Write() method. When we run it, we discover that the values are printed without a new line.

An example of Console.WriteLine()

using System;
class HelloWorld {
static void Main() {
Console.WriteLine("Hello");
Console.WriteLine("and welcome ");
Console.WriteLine("to");
Console.WriteLine("Edpresso!");
}
}

Explanation

  • Lines 4-7: We print some texts to the console using the Console.WriteLine() method. When we run it, we discover that the values are printed with new lines.
New on Educative
Learn any Language for FREE all September 🎉
For the entire month of September, get unlimited access to our entire catalog of beginner coding resources.
🎁 G i v e a w a y
30 Days of Code
Complete Educative’s daily coding challenge every day in September, and win exciting Prizes.

Free Resources