In C#, System.Console is the standard way to talk to the terminal: print messages with WriteLine(), ask for text with ReadLine(), and optionally clear the screen or redirect streams.
Most beginner programs start with using System; and then call Console.WriteLine(...). Input usually comes from the keyboard (standard input); output goes to the screen (standard output).
This page introduces Console. The Console Methods index lists every method guide in this series.
Interactive vs redirected.
Cursor, window, and some clear/beep APIs need a real console window. When input/output is redirected (files, pipes), prefer stream-safe Write/ReadLine patterns and wrap window APIs in try/catch.
Syntax
C# Syntax
Common first calls:
C#
Console.WriteLine("Hello"); // print a line
Console.Write("Name: "); // same-line prompt
string? s = Console.ReadLine(); // read a line (null at EOF)
Console.WriteLine("Hi, " + s);
Reference
stdin and stdout
A quick map of the streams Console uses:
Stream
Typical source
Common APIs
stdin (In)
Keyboard
ReadLine, Read, SetIn
stdout (Out)
Screen
Write, WriteLine, SetOut
stderr (Error)
Diagnostics
Error.WriteLine, SetError
Code
C# Examples
Three short programs that show Console output and input.
Example 1 — Print Lines with WriteLine
A first program that shows how standard output works.
C#
using System;
class Program {
static void Main() {
Console.WriteLine("Hello, Console!");
Console.WriteLine("2 + 2 = " + (2 + 2));
}
}
Output
Hello, Console!
2 + 2 = 4
How It Works
stdout.WriteLine sends text to standard output—the console screen in a normal app.
Newline included. Each call ends the line so the next message starts below.
Mix text and values. Concatenate numbers into the message for quick results.
Example 2 — Ask for Input with ReadLine
Prompt on the same line with Write, then read a full line.
C#
using System;
class Program {
static void Main() {
Console.Write("Your name: ");
string name = Console.ReadLine() ?? "friend";
Console.WriteLine("Hello, " + name + "!");
}
}
Output
Your name: Sam
Hello, Sam!
How It Works
Same-line prompt.Write leaves the cursor after the label.
Sample typing. sample output shows the user entering Sam.
Null at EOF.?? "friend" covers the case when ReadLine returns null.
Example 3 — See the Difference Side by Side
Use Write for pieces on one row, then finish with WriteLine.
C#
using System;
class Program {
static void Main() {
Console.Write("A");
Console.Write("B");
Console.WriteLine("C");
Console.WriteLine("Next line");
}
}
Output
ABC
Next line
How It Works
No break yet. Two Write calls keep A and B together.
Finish the row.WriteLine("C") prints C and advances.
New line. The final message starts on the next row.
Continue
Next: C# Console Methods Index
After you know what Console is for, open the method index for a full tutorial on each System.Console API.