C# Console Read() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Console

Definition

In C#, Console.Read pulls the next character from standard input and returns it as an int (the Unicode code point). When there is no more input, it returns -1.

It is lower-level than ReadLine. You often cast the result to char after checking that it is not -1. For whole lines of text, prefer ReadLine; for a single key press with details, prefer ReadKey.

This is a static member of System.Console. You call it with the type name, such as Console.Read(...). Console is the everyday API for reading from standard input and writing to standard output in C# console apps.

Syntax

Call Console.Read(), then test for -1 before casting to char.

C#
int code = Console.Read();
if (code != -1) {
    char ch = (char)code;
}
CallWhat it does
Console.Read()Next character as int, or -1 at EOF.

Input is usually line-buffered in a terminal: the user may need to press Enter before characters become available.

Library declarations
C#
public static int Read();

Parameters

ParameterDescription
NoneRead() takes no parameters.

Return Value

Return ValueDescription
int (0–…)The next character’s code point.
-1End of input (EOF).

C# Examples

Example 1 — Read a Character After Enter

Ask for a letter, read one character with Read, then show its code.

C#
using System;

class Program {
    static void Main() {
        Console.Write("Type a letter and press Enter: ");
        int code = Console.Read();
        if (code == -1) {
            Console.WriteLine("No input");
            return;
        }
        char ch = (char)code;
        Console.WriteLine();
        Console.WriteLine("You typed: " + ch);
        Console.WriteLine("Code: " + code);
    }
}

How It Works

  1. Prompt first. Write keeps the cursor on the same line as the question.
  2. Sample typing. Output shows the user typing A and Enter.
  3. Int then cast. 65 is the code for 'A'; cast only after the EOF check.
  4. Extra newline. An empty WriteLine keeps the report tidy after the Enter key.

Example 2 — Count Characters Until End

Loop while Read returns values other than -1.

C#
using System;

class Program {
    static void Main() {
        Console.WriteLine("Type text, then Ctrl+Z (Windows) or Ctrl+D and Enter:");
        int count = 0;
        int code;
        while ((code = Console.Read()) != -1) {
            count++;
        }
        Console.WriteLine("Characters read: " + count);
    }
}

How It Works

  1. Loop condition. Assignment inside while keeps reading until EOF.
  2. Sample stream. Typing hi plus Enter typically yields three codes (h, i, newline).
  3. -1 stops. End-of-file ends the loop cleanly.
  4. Count only. This demo tallies characters; it does not echo them.

Example 3 — Test Whether the First Char Is a Digit

Read one character and classify it with char.IsDigit.

C#
using System;

class Program {
    static void Main() {
        Console.Write("First character: ");
        int code = Console.Read();
        if (code < 0) {
            Console.WriteLine("EOF");
            return;
        }
        char ch = (char)code;
        Console.WriteLine();
        Console.WriteLine(char.IsDigit(ch) ? "Digit" : "Not a digit");
    }
}

How It Works

  1. Guard EOF. Negative means no character arrived.
  2. Typed 7. sample output shows a digit being entered.
  3. IsDigit. Classifies the character without parsing a whole number string.
  4. Read vs ReadLine. Here only the first character matters, so Read fits.

Frequently Asked Questions

The next character as an int code point, or -1 when input ends.
Most consoles buffer a line. Characters often become available after Enter.
Read returns one character as int. ReadLine returns a whole string line (or null at EOF).
ReadKey returns a ConsoleKeyInfo for a key press and can hide the echo. Read is stream-oriented.
Ensure the return value is not -1, then cast to char.

Next: ReadKey()

Read a single key press; optionally hide it with intercept with System.Console.

ReadKey() tutorial →

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.

13 people found this page helpful