Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

write
writeln
console
c#
communitycreator

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

Theodore Kelechukwu Onyejiaku

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!");
    }
}
Using the Console.Write() method to print values to the console

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!");
    }
}
Printing values to the console using Console.WriteLine() in C#

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.

RELATED TAGS

write
writeln
console
c#
communitycreator

CONTRIBUTOR

Theodore Kelechukwu Onyejiaku
RELATED COURSES

View all Courses

Keep Exploring