C# Console

Beginner
7 min read
Updated: Nov 2026
3 examples
Console

Definition and Usage

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.

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);

stdin and stdout

A quick map of the streams Console uses:

StreamTypical sourceCommon APIs
stdin (In)KeyboardReadLine, Read, SetIn
stdout (Out)ScreenWrite, WriteLine, SetOut
stderr (Error)DiagnosticsError.WriteLine, SetError

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));
    }
}

How It Works

  1. stdout. WriteLine sends text to standard output—the console screen in a normal app.
  2. Newline included. Each call ends the line so the next message starts below.
  3. 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 + "!");
    }
}

How It Works

  1. Same-line prompt. Write leaves the cursor after the label.
  2. Sample typing. sample output shows the user entering Sam.
  3. 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");
    }
}

How It Works

  1. No break yet. Two Write calls keep A and B together.
  2. Finish the row. WriteLine("C") prints C and advances.
  3. New line. The final message starts on the next row.

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.

Start withWhy
WriteLine()Print a finished line of text
ReadLine()Read a line of keyboard input
Write()Same-line prompts and partial text
Clear()Clear the screen for simple menus

Full list: C# Console Methods index (/c-sharp/console/method).

Frequently Asked Questions

It is the standard C# API for reading from stdin and writing to stdout/stderr in console applications—WriteLine, ReadLine, Clear, and related helpers.
stdin is the input stream (often the keyboard). stdout is the normal output stream (often the screen). stderr is for diagnostics.
Write keeps the cursor on the same line. WriteLine ends the line. Use Write for prompts; WriteLine for finished messages.
null. Empty Enter returns "". Console.Read returns -1 at EOF.
Open the C# Console Methods index. It lists WriteLine, ReadLine, ReadKey, Clear, SetOut, and the rest.

Browse every Console method

Open the methods index for categorized guides with examples and FAQs.

Console Methods Index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful