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.