VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/console-class-in-c-sharp/

⇱ C# Console Class - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C# Console Class

Last Updated : 9 Jun, 2026

Console class is used to handle input, output and error operations in console applications. It is available in the System namespace and provides methods like Write(), WriteLine() and ReadLine() for interacting with users through the console window. Console applications allow users to enter input using the keyboard and view text-based output on the screen.

The console has two main components:

  • Screen Buffer: Stores text output before displaying it on the console window.
  • Console Window: Displays the visible output of the console application.

Output
Hello, From GeeksforGeeks!

Running a C# Console Program in CMD

To run a C# console program using Command Prompt:

1. Save the file with .cs extension, for example Program.cs

2. Open Command Prompt in that folder.

3. Compile the program using:

csc Program.cs

4. Run the generated executable file:

Program.exe

This will display the output in the console window.

Properties

Properties

Description

BackgroundColor

Gets or sets the background colour of the console.

BufferHeight

Gets or sets the height of the buffer area.

BufferWidth

Gets or sets the width of the buffer area.

CapsLock

Gets a value indicating whether the CAPS LOCK keyboard toggle is turned on or turned off.

CursorLeft

Gets or sets the column position of the cursor within the buffer area.

CursorSize

Gets or sets the height of the cursor within a character cell.

CursorTop

Gets or sets the row position of the cursor within the buffer area.

CursorVisible

Gets or sets a value indicating whether the cursor is visible.

Error

Gets the standard error output stream.

ForegroundColor

Gets or sets the foreground colour of the console.

In

Gets the standard input stream.

InputEncoding

Gets or sets the encoding the console uses to read input.

IsErrorRedirected

Gets a value that indicates whether the error output stream has been redirected from the standard error stream.

InputRedirected

Gets a value that indicates whether input has been redirected from the standard input stream.

OutputRedirected

Gets a value that indicates whether output has been redirected from the standard output stream.

KeyAvailable

Gets a value indicating whether a key press is available in the input stream.

LargestWindowHeight

Gets the largest possible number of console window rows, based on the current font and screen resolution.

LargestWindowWidth

Gets the largest possible number of console window columns, based on the current font and screen resolution.

NumberLock

Gets a value indicating whether the NUM LOCK keyboard toggle is turned on or turned off.

Out

Gets the standard output stream.

OutputEncoding

Gets or sets the encoding the console uses to write output.

Title

Gets or sets the title to display in the console title bar.

TreatControlCAsInput

Gets or sets a value indicating whether the combination of the Control modifier key and C console key (Ctrl+C) is treated as ordinary input or as an interruption that is handled by the operating system.

WindowHeight

Gets or sets the height of the console window area.

WindowLeft

Gets or sets the leftmost position of the console window area relative to the screen buffer.

WindowTop

Gets or sets the top position of the console window area relative to the screen buffer.

WindowWidth

Gets or sets the width of the console window.

Example: Getting Console Colors

Output

👁 ConsoleClassExample
Output

Methods

Method

Description

Beep()

Plays the sound of a beep through the console speaker.

Clear()

Clears the console buffer and corresponding console window of display information.

MoveBufferArea()

Copies a specified source area of the screen buffer to a specified destination area.

OpenStandardError()

Acquires the standard error stream.

OpenStandardInput()

Acquires the standard input stream.

OpenStandardOutput()

Acquires the standard output stream.

Read()

Reads the next character from the standard input stream.

ReadKey()

Obtains the next character or function key pressed by the user. The pressed key is displayed in the console window.

ReadLine()

Reads the next line of characters from the standard input stream.

ResetColor()

Sets the foreground and background console colours to their defaults.

SetBufferSize(Int32, Int32)

Sets the height and width of the screen buffer area to the specified values.

SetCursorPosition(Int32, Int32)

Sets the position of the cursor.

SetError(TextWriter)

Sets the Error property to the specified TextWriter object.

SetIn(TextReader)

Sets the In property to the specified TextReader object.

SetOut(TextWriter)

Sets the Out property to the specified TextWriter object.

SetWindowPosition(Int32, Int32)

Sets the position of the console window relative to the screen buffer.

SetWindowSize(Int32, Int32)

Sets the height and width of the console window to the specified values.

Write()

Writes the text representation of the specified value or values to the standard output stream.

WriteLine()

Writes the specified data, followed by the current line terminator, to the standard output stream.

Example: Using WriteLine() Method


Output
Welcome to GeeksforGeeks
This is a tutorial on the Console Class.

Events

Console class provides events used to execute certain programs when some event is triggered such as cancelling an operation or modifying console settings dynamically.

Example: CancelKeyPress Event Occurs when the Control modifier key (Ctrl) and either the C console key (C) or the Break key are pressed simultaneously (Ctrl+C or Ctrl+Break).

Output

Comment
Article Tags:

Explore