mscorlib(4.0.0.0) API with additions
System.Console Class Reference

Represents the standard input, output, and error streams for console applications. This class cannot be inherited.To browse the .NET Framework source code for this type, see the Reference Source. More...

Static Public Member Functions

static void Beep ()
 Plays the sound of a beep through the console speaker. More...
 
static void Beep (int frequency, int duration)
 Plays the sound of a beep of a specified frequency and duration through the console speaker. More...
 
static void Clear ()
 Clears the console buffer and corresponding console window of display information. More...
 
static void ResetColor ()
 Sets the foreground and background console colors to their defaults. More...
 
static void MoveBufferArea (int sourceLeft, int sourceTop, int sourceWidth, int sourceHeight, int targetLeft, int targetTop)
 Copies a specified source area of the screen buffer to a specified destination area. More...
 
static unsafe void MoveBufferArea (int sourceLeft, int sourceTop, int sourceWidth, int sourceHeight, int targetLeft, int targetTop, char sourceChar, ConsoleColor sourceForeColor, ConsoleColor sourceBackColor)
 Copies a specified source area of the screen buffer to a specified destination area. More...
 
static void SetBufferSize (int width, int height)
 Sets the height and width of the screen buffer area to the specified values. More...
 
static unsafe void SetWindowSize (int width, int height)
 Sets the height and width of the console window to the specified values. More...
 
static unsafe void SetWindowPosition (int left, int top)
 Sets the position of the console window relative to the screen buffer. More...
 
static void SetCursorPosition (int left, int top)
 Sets the position of the cursor. More...
 
static ConsoleKeyInfo ReadKey ()
 Obtains the next character or function key pressed by the user. The pressed key is displayed in the console window. More...
 
static ConsoleKeyInfo ReadKey (bool intercept)
 Obtains the next character or function key pressed by the user. The pressed key is optionally displayed in the console window. More...
 
static Stream OpenStandardError ()
 Acquires the standard error stream. More...
 
static Stream OpenStandardError (int bufferSize)
 Acquires the standard error stream, which is set to a specified buffer size. More...
 
static Stream OpenStandardInput ()
 Acquires the standard input stream. More...
 
static Stream OpenStandardInput (int bufferSize)
 Acquires the standard input stream, which is set to a specified buffer size. More...
 
static Stream OpenStandardOutput ()
 Acquires the standard output stream. More...
 
static Stream OpenStandardOutput (int bufferSize)
 Acquires the standard output stream, which is set to a specified buffer size. More...
 
static void SetIn (TextReader newIn)
 Sets the P:System.Console.In property to the specified T:System.IO.TextReader object. More...
 
static void SetOut (TextWriter newOut)
 Sets the P:System.Console.Out property to the specified T:System.IO.TextWriter object. More...
 
static void SetError (TextWriter newError)
 Sets the P:System.Console.Error property to the specified T:System.IO.TextWriter object. More...
 
static int Read ()
 Reads the next character from the standard input stream. More...
 
static string ReadLine ()
 Reads the next line of characters from the standard input stream. More...
 
static void WriteLine ()
 Writes the current line terminator to the standard output stream. More...
 
static void WriteLine (bool value)
 Writes the text representation of the specified Boolean value, followed by the current line terminator, to the standard output stream. More...
 
static void WriteLine (char value)
 Writes the specified Unicode character, followed by the current line terminator, value to the standard output stream. More...
 
static void WriteLine (char[] buffer)
 Writes the specified array of Unicode characters, followed by the current line terminator, to the standard output stream. More...
 
static void WriteLine (char[] buffer, int index, int count)
 Writes the specified subarray of Unicode characters, followed by the current line terminator, to the standard output stream. More...
 
static void WriteLine (decimal value)
 Writes the text representation of the specified T:System.Decimal value, followed by the current line terminator, to the standard output stream. More...
 
static void WriteLine (double value)
 Writes the text representation of the specified double-precision floating-point value, followed by the current line terminator, to the standard output stream. More...
 
static void WriteLine (float value)
 Writes the text representation of the specified single-precision floating-point value, followed by the current line terminator, to the standard output stream. More...
 
static void WriteLine (int value)
 Writes the text representation of the specified 32-bit signed integer value, followed by the current line terminator, to the standard output stream. More...
 
static void WriteLine (uint value)
 Writes the text representation of the specified 32-bit unsigned integer value, followed by the current line terminator, to the standard output stream. More...
 
static void WriteLine (long value)
 Writes the text representation of the specified 64-bit signed integer value, followed by the current line terminator, to the standard output stream. More...
 
static void WriteLine (ulong value)
 Writes the text representation of the specified 64-bit unsigned integer value, followed by the current line terminator, to the standard output stream. More...
 
static void WriteLine (object value)
 Writes the text representation of the specified object, followed by the current line terminator, to the standard output stream. More...
 
static void WriteLine (string value)
 Writes the specified string value, followed by the current line terminator, to the standard output stream. More...
 
static void WriteLine (string format, object arg0)
 Writes the text representation of the specified object, followed by the current line terminator, to the standard output stream using the specified format information. More...
 
static void WriteLine (string format, object arg0, object arg1)
 Writes the text representation of the specified objects, followed by the current line terminator, to the standard output stream using the specified format information. More...
 
static void WriteLine (string format, object arg0, object arg1, object arg2)
 Writes the text representation of the specified objects, followed by the current line terminator, to the standard output stream using the specified format information. More...
 
static void WriteLine (string format, object arg0, object arg1, object arg2, object arg3, __arglist)
 
static void WriteLine (string format, params object[] arg)
 Writes the text representation of the specified array of objects, followed by the current line terminator, to the standard output stream using the specified format information. More...
 
static void Write (string format, object arg0)
 Writes the text representation of the specified object to the standard output stream using the specified format information. More...
 
static void Write (string format, object arg0, object arg1)
 Writes the text representation of the specified objects to the standard output stream using the specified format information. More...
 
static void Write (string format, object arg0, object arg1, object arg2)
 Writes the text representation of the specified objects to the standard output stream using the specified format information. More...
 
static void Write (string format, object arg0, object arg1, object arg2, object arg3, __arglist)
 
static void Write (string format, params object[] arg)
 Writes the text representation of the specified array of objects to the standard output stream using the specified format information. More...
 
static void Write (bool value)
 Writes the text representation of the specified Boolean value to the standard output stream. More...
 
static void Write (char value)
 Writes the specified Unicode character value to the standard output stream. More...
 
static void Write (char[] buffer)
 Writes the specified array of Unicode characters to the standard output stream. More...
 
static void Write (char[] buffer, int index, int count)
 Writes the specified subarray of Unicode characters to the standard output stream. More...
 
static void Write (double value)
 Writes the text representation of the specified double-precision floating-point value to the standard output stream. More...
 
static void Write (decimal value)
 Writes the text representation of the specified T:System.Decimal value to the standard output stream. More...
 
static void Write (float value)
 Writes the text representation of the specified single-precision floating-point value to the standard output stream. More...
 
static void Write (int value)
 Writes the text representation of the specified 32-bit signed integer value to the standard output stream. More...
 
static void Write (uint value)
 Writes the text representation of the specified 32-bit unsigned integer value to the standard output stream. More...
 
static void Write (long value)
 Writes the text representation of the specified 64-bit signed integer value to the standard output stream. More...
 
static void Write (ulong value)
 Writes the text representation of the specified 64-bit unsigned integer value to the standard output stream. More...
 
static void Write (object value)
 Writes the text representation of the specified object to the standard output stream. More...
 
static void Write (string value)
 Writes the specified string value to the standard output stream. More...
 

Properties

static bool IsInputRedirected [get]
 Gets a value that indicates whether input has been redirected from the standard input stream. More...
 
static bool IsOutputRedirected [get]
 Gets a value that indicates whether output has been redirected from the standard output stream. More...
 
static bool IsErrorRedirected [get]
 Gets a value that indicates whether the error output stream has been redirected from the standard error stream. More...
 
static TextReader In [get]
 Gets the standard input stream. More...
 
static TextWriter Out [get]
 Gets the standard output stream. More...
 
static TextWriter Error [get]
 Gets the standard error output stream. More...
 
static Encoding InputEncoding [get, set]
 Gets or sets the encoding the console uses to read input. More...
 
static Encoding OutputEncoding [get, set]
 Gets or sets the encoding the console uses to write output. More...
 
static ConsoleColor BackgroundColor [get, set]
 Gets or sets the background color of the console. More...
 
static ConsoleColor ForegroundColor [get, set]
 Gets or sets the foreground color of the console. More...
 
static int BufferHeight [get, set]
 Gets or sets the height of the buffer area. More...
 
static int BufferWidth [get, set]
 Gets or sets the width of the buffer area. More...
 
static int WindowHeight [get, set]
 Gets or sets the height of the console window area. More...
 
static int WindowWidth [get, set]
 Gets or sets the width of the console window. More...
 
static int LargestWindowWidth [get]
 Gets the largest possible number of console window columns, based on the current font and screen resolution. More...
 
static int LargestWindowHeight [get]
 Gets the largest possible number of console window rows, based on the current font and screen resolution. More...
 
static int WindowLeft [get, set]
 Gets or sets the leftmost position of the console window area relative to the screen buffer. More...
 
static int WindowTop [get, set]
 Gets or sets the top position of the console window area relative to the screen buffer. More...
 
static int CursorLeft [get, set]
 Gets or sets the column position of the cursor within the buffer area. More...
 
static int CursorTop [get, set]
 Gets or sets the row position of the cursor within the buffer area. More...
 
static int CursorSize [get, set]
 Gets or sets the height of the cursor within a character cell. More...
 
static bool CursorVisible [get, set]
 Gets or sets a value indicating whether the cursor is visible. More...
 
static string Title [get, set]
 Gets or sets the title to display in the console title bar. More...
 
static bool KeyAvailable [get]
 Gets a value indicating whether a key press is available in the input stream. More...
 
static bool NumberLock [get]
 Gets a value indicating whether the NUM LOCK keyboard toggle is turned on or turned off. More...
 
static bool CapsLock [get]
 Gets a value indicating whether the CAPS LOCK keyboard toggle is turned on or turned off. More...
 
static bool? TreatControlCAsInput [get, set]
 Gets or sets a value indicating whether the combination of the F:System.ConsoleModifiers.Control modifier key and F:System.ConsoleKey.C console key (Ctrl+C) is treated as ordinary input or as an interruption that is handled by the operating system. More...
 
static ConsoleCancelEventHandler CancelKeyPress
 Occurs when the F:System.ConsoleModifiers.Control modifier key (Ctrl) and either the F:System.ConsoleKey.C console key (C) or the Break key are pressed simultaneously (Ctrl+C or Ctrl+Break). More...
 

Detailed Description

Represents the standard input, output, and error streams for console applications. This class cannot be inherited.To browse the .NET Framework source code for this type, see the Reference Source.

Definition at line 15 of file Console.cs.

Member Function Documentation

◆ Beep() [1/2]

static void System.Console.Beep ( )
static

Plays the sound of a beep through the console speaker.

Exceptions
T:System.Security.HostProtectionExceptionThis method was executed on a server, such as SQL Server, that does not permit access to a user interface.

Definition at line 1077 of file Console.cs.

◆ Beep() [2/2]

static void System.Console.Beep ( int  frequency,
int  duration 
)
static

Plays the sound of a beep of a specified frequency and duration through the console speaker.

Parameters
frequencyThe frequency of the beep, ranging from 37 to 32767 hertz.
durationThe duration of the beep measured in milliseconds.
Exceptions
T:System.ArgumentOutOfRangeExceptionfrequency is less than 37 or more than 32767 hertz.-or- duration is less than or equal to zero.
T:System.Security.HostProtectionExceptionThis method was executed on a server, such as SQL Server, that does not permit access to the console.

Definition at line 1091 of file Console.cs.

◆ Clear()

static void System.Console.Clear ( )
static

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

Exceptions
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 1107 of file Console.cs.

◆ MoveBufferArea() [1/2]

static void System.Console.MoveBufferArea ( int  sourceLeft,
int  sourceTop,
int  sourceWidth,
int  sourceHeight,
int  targetLeft,
int  targetTop 
)
static

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

Parameters
sourceLeftThe leftmost column of the source area.
sourceTopThe topmost row of the source area.
sourceWidthThe number of columns in the source area.
sourceHeightThe number of rows in the source area.
targetLeftThe leftmost column of the destination area.
targetTopThe topmost row of the destination area.
Exceptions
T:System.ArgumentOutOfRangeExceptionOne or more of the parameters is less than zero.-or- sourceLeft or targetLeft is greater than or equal to P:System.Console.BufferWidth.-or- sourceTop or targetTop is greater than or equal to P:System.Console.BufferHeight.-or- sourceTop + sourceHeight is greater than or equal to P:System.Console.BufferHeight.-or- sourceLeft + sourceWidth is greater than or equal to P:System.Console.BufferWidth.
T:System.Security.SecurityExceptionThe user does not have permission to perform this action.
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 1188 of file Console.cs.

◆ MoveBufferArea() [2/2]

static unsafe void System.Console.MoveBufferArea ( int  sourceLeft,
int  sourceTop,
int  sourceWidth,
int  sourceHeight,
int  targetLeft,
int  targetTop,
char  sourceChar,
ConsoleColor  sourceForeColor,
ConsoleColor  sourceBackColor 
)
static

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

Parameters
sourceLeftThe leftmost column of the source area.
sourceTopThe topmost row of the source area.
sourceWidthThe number of columns in the source area.
sourceHeightThe number of rows in the source area.
targetLeftThe leftmost column of the destination area.
targetTopThe topmost row of the destination area.
sourceCharThe character used to fill the source area.
sourceForeColorThe foreground color used to fill the source area.
sourceBackColorThe background color used to fill the source area.
Exceptions
T:System.ArgumentOutOfRangeExceptionOne or more of the parameters is less than zero.-or- sourceLeft or targetLeft is greater than or equal to P:System.Console.BufferWidth.-or- sourceTop or targetTop is greater than or equal to P:System.Console.BufferHeight.-or- sourceTop + sourceHeight is greater than or equal to P:System.Console.BufferHeight.-or- sourceLeft + sourceWidth is greater than or equal to P:System.Console.BufferWidth.
T:System.ArgumentExceptionOne or both of the color parameters is not a member of the T:System.ConsoleColor enumeration.
T:System.Security.SecurityExceptionThe user does not have permission to perform this action.
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 1212 of file Console.cs.

◆ OpenStandardError() [1/2]

static Stream System.Console.OpenStandardError ( )
static

Acquires the standard error stream.

Returns
The standard error stream.

Definition at line 1695 of file Console.cs.

◆ OpenStandardError() [2/2]

static Stream System.Console.OpenStandardError ( int  bufferSize)
static

Acquires the standard error stream, which is set to a specified buffer size.

Parameters
bufferSizeThe internal stream buffer size.
Returns
The standard error stream.
Exceptions
T:System.ArgumentOutOfRangeExceptionbufferSize is less than or equal to zero.

Definition at line 1706 of file Console.cs.

◆ OpenStandardInput() [1/2]

static Stream System.Console.OpenStandardInput ( )
static

Acquires the standard input stream.

Returns
The standard input stream.

Definition at line 1718 of file Console.cs.

◆ OpenStandardInput() [2/2]

static Stream System.Console.OpenStandardInput ( int  bufferSize)
static

Acquires the standard input stream, which is set to a specified buffer size.

Parameters
bufferSizeThe internal stream buffer size.
Returns
The standard input stream.
Exceptions
T:System.ArgumentOutOfRangeExceptionbufferSize is less than or equal to zero.

Definition at line 1729 of file Console.cs.

◆ OpenStandardOutput() [1/2]

static Stream System.Console.OpenStandardOutput ( )
static

Acquires the standard output stream.

Returns
The standard output stream.

Definition at line 1741 of file Console.cs.

◆ OpenStandardOutput() [2/2]

static Stream System.Console.OpenStandardOutput ( int  bufferSize)
static

Acquires the standard output stream, which is set to a specified buffer size.

Parameters
bufferSizeThe internal stream buffer size.
Returns
The standard output stream.
Exceptions
T:System.ArgumentOutOfRangeExceptionbufferSize is less than or equal to zero.

Definition at line 1752 of file Console.cs.

◆ Read()

static int System.Console.Read ( )
static

Reads the next character from the standard input stream.

Returns
The next character from the input stream, or negative one (-1) if there are currently no more characters to be read.
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 1831 of file Console.cs.

◆ ReadKey() [1/2]

static ConsoleKeyInfo System.Console.ReadKey ( )
static

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

Returns
An object that describes the T:System.ConsoleKey constant and Unicode character, if any, that correspond to the pressed console key. The T:System.ConsoleKeyInfo object also describes, in a bitwise combination of T:System.ConsoleModifiers values, whether one or more Shift, Alt, or Ctrl modifier keys was pressed simultaneously with the console key.
Exceptions
T:System.InvalidOperationExceptionThe P:System.Console.In property is redirected from some stream other than the console.

Definition at line 1536 of file Console.cs.

◆ ReadKey() [2/2]

static ConsoleKeyInfo System.Console.ReadKey ( bool  intercept)
static

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

Parameters
interceptDetermines whether to display the pressed key in the console window. true to not display the pressed key; otherwise, false.
Returns
An object that describes the T:System.ConsoleKey constant and Unicode character, if any, that correspond to the pressed console key. The T:System.ConsoleKeyInfo object also describes, in a bitwise combination of T:System.ConsoleModifiers values, whether one or more Shift, Alt, or Ctrl modifier keys was pressed simultaneously with the console key.
Exceptions
T:System.InvalidOperationExceptionThe P:System.Console.In property is redirected from some stream other than the console.

Definition at line 1574 of file Console.cs.

◆ ReadLine()

static string System.Console.ReadLine ( )
static

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

Returns
The next line of characters from the input stream, or null if no more lines are available.
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.
T:System.OutOfMemoryExceptionThere is insufficient memory to allocate a buffer for the returned string.
T:System.ArgumentOutOfRangeExceptionThe number of characters in the next line of characters is greater than F:System.Int32.MaxValue.

Definition at line 1843 of file Console.cs.

◆ ResetColor()

static void System.Console.ResetColor ( )
static

Sets the foreground and background console colors to their defaults.

Exceptions
T:System.Security.SecurityExceptionThe user does not have permission to perform this action.
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 1162 of file Console.cs.

◆ SetBufferSize()

static void System.Console.SetBufferSize ( int  width,
int  height 
)
static

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

Parameters
widthThe width of the buffer area measured in columns.
heightThe height of the buffer area measured in rows.
Exceptions
T:System.ArgumentOutOfRangeExceptionheight or width is less than or equal to zero.-or- height or width is greater than or equal to F:System.Int16.MaxValue.-or- width is less than P:System.Console.WindowLeft + P:System.Console.WindowWidth.-or- height is less than P:System.Console.WindowTop + P:System.Console.WindowHeight.
T:System.Security.SecurityExceptionThe user does not have permission to perform this action.
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 1358 of file Console.cs.

◆ SetCursorPosition()

static void System.Console.SetCursorPosition ( int  left,
int  top 
)
static

Sets the position of the cursor.

Parameters
leftThe column position of the cursor. Columns are numbered from left to right starting at 0.
topThe row position of the cursor. Rows are numbered from top to bottom starting at 0.
Exceptions
T:System.ArgumentOutOfRangeExceptionleft or top is less than zero.-or- left is greater than or equal to P:System.Console.BufferWidth.-or- top is greater than or equal to P:System.Console.BufferHeight.
T:System.Security.SecurityExceptionThe user does not have permission to perform this action.
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 1496 of file Console.cs.

◆ SetError()

static void System.Console.SetError ( TextWriter  newError)
static

Sets the P:System.Console.Error property to the specified T:System.IO.TextWriter object.

Parameters
newErrorA stream that is the new standard error output.
Exceptions
T:System.ArgumentNullExceptionnewError is null.
T:System.Security.SecurityExceptionThe caller does not have the required permission.

Definition at line 1811 of file Console.cs.

◆ SetIn()

static void System.Console.SetIn ( TextReader  newIn)
static

Sets the P:System.Console.In property to the specified T:System.IO.TextReader object.

Parameters
newInA stream that is the new standard input.
Exceptions
T:System.ArgumentNullExceptionnewIn is null.
T:System.Security.SecurityExceptionThe caller does not have the required permission.

Definition at line 1768 of file Console.cs.

◆ SetOut()

static void System.Console.SetOut ( TextWriter  newOut)
static

Sets the P:System.Console.Out property to the specified T:System.IO.TextWriter object.

Parameters
newOutA stream that is the new standard output.
Exceptions
T:System.ArgumentNullExceptionnewOut is null.
T:System.Security.SecurityExceptionThe caller does not have the required permission.

Definition at line 1789 of file Console.cs.

◆ SetWindowPosition()

static unsafe void System.Console.SetWindowPosition ( int  left,
int  top 
)
static

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

Parameters
leftThe column position of the upper left corner of the console window.
topThe row position of the upper left corner of the console window.
Exceptions
T:System.ArgumentOutOfRangeExceptionleft or top is less than zero.-or- left + P:System.Console.WindowWidth is greater than P:System.Console.BufferWidth.-or- top + P:System.Console.WindowHeight is greater than P:System.Console.BufferHeight.
T:System.Security.SecurityExceptionThe user does not have permission to perform this action.
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 1461 of file Console.cs.

◆ SetWindowSize()

static unsafe void System.Console.SetWindowSize ( int  width,
int  height 
)
static

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

Parameters
widthThe width of the console window measured in columns.
heightThe height of the console window measured in rows.
Exceptions
T:System.ArgumentOutOfRangeExceptionwidth or height is less than or equal to zero.-or- width plus P:System.Console.WindowLeft or height plus P:System.Console.WindowTop is greater than or equal to F:System.Int16.MaxValue. -or- width or height is greater than the largest possible window width or height for the current screen resolution and console font.
T:System.Security.SecurityExceptionThe user does not have permission to perform this action.
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 1390 of file Console.cs.

◆ Write() [1/17]

static void System.Console.Write ( string  format,
object  arg0 
)
static

Writes the text representation of the specified object to the standard output stream using the specified format information.

Parameters
formatA composite format string (see Remarks).
arg0An object to write using format .
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.
T:System.ArgumentNullExceptionformat is null.
T:System.FormatExceptionThe format specification in format is invalid.

Definition at line 2091 of file Console.cs.

◆ Write() [2/17]

static void System.Console.Write ( string  format,
object  arg0,
object  arg1 
)
static

Writes the text representation of the specified objects to the standard output stream using the specified format information.

Parameters
formatA composite format string (see Remarks).
arg0The first object to write using format .
arg1The second object to write using format .
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.
T:System.ArgumentNullExceptionformat is null.
T:System.FormatExceptionThe format specification in format is invalid.

Definition at line 2106 of file Console.cs.

◆ Write() [3/17]

static void System.Console.Write ( string  format,
object  arg0,
object  arg1,
object  arg2 
)
static

Writes the text representation of the specified objects to the standard output stream using the specified format information.

Parameters
formatA composite format string (see Remarks).
arg0The first object to write using format .
arg1The second object to write using format .
arg2The third object to write using format .
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.
T:System.ArgumentNullExceptionformat is null.
T:System.FormatExceptionThe format specification in format is invalid.

Definition at line 2122 of file Console.cs.

◆ Write() [4/17]

static void System.Console.Write ( string  format,
params object []  arg 
)
static

Writes the text representation of the specified array of objects to the standard output stream using the specified format information.

Parameters
formatA composite format string (see Remarks).
argAn array of objects to write using format .
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.
T:System.ArgumentNullExceptionformat or arg is null.
T:System.FormatExceptionThe format specification in format is invalid.

Definition at line 2155 of file Console.cs.

◆ Write() [5/17]

static void System.Console.Write ( bool  value)
static

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

Parameters
valueThe value to write.
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 2172 of file Console.cs.

◆ Write() [6/17]

static void System.Console.Write ( char  value)
static

Writes the specified Unicode character value to the standard output stream.

Parameters
valueThe value to write.
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 2182 of file Console.cs.

◆ Write() [7/17]

static void System.Console.Write ( char []  buffer)
static

Writes the specified array of Unicode characters to the standard output stream.

Parameters
bufferA Unicode character array.
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 2192 of file Console.cs.

◆ Write() [8/17]

static void System.Console.Write ( char []  buffer,
int  index,
int  count 
)
static

Writes the specified subarray of Unicode characters to the standard output stream.

Parameters
bufferAn array of Unicode characters.
indexThe starting position in buffer .
countThe number of characters to write.
Exceptions
T:System.ArgumentNullExceptionbuffer is null.
T:System.ArgumentOutOfRangeExceptionindex or count is less than zero.
T:System.ArgumentExceptionindex plus count specify a position that is not within buffer .
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 2210 of file Console.cs.

◆ Write() [9/17]

static void System.Console.Write ( double  value)
static

Writes the text representation of the specified double-precision floating-point value to the standard output stream.

Parameters
valueThe value to write.
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 2220 of file Console.cs.

◆ Write() [10/17]

static void System.Console.Write ( decimal  value)
static

Writes the text representation of the specified T:System.Decimal value to the standard output stream.

Parameters
valueThe value to write.
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 2230 of file Console.cs.

◆ Write() [11/17]

static void System.Console.Write ( float  value)
static

Writes the text representation of the specified single-precision floating-point value to the standard output stream.

Parameters
valueThe value to write.
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 2240 of file Console.cs.

◆ Write() [12/17]

static void System.Console.Write ( int  value)
static

Writes the text representation of the specified 32-bit signed integer value to the standard output stream.

Parameters
valueThe value to write.
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 2250 of file Console.cs.

◆ Write() [13/17]

static void System.Console.Write ( uint  value)
static

Writes the text representation of the specified 32-bit unsigned integer value to the standard output stream.

Parameters
valueThe value to write.
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 2261 of file Console.cs.

◆ Write() [14/17]

static void System.Console.Write ( long  value)
static

Writes the text representation of the specified 64-bit signed integer value to the standard output stream.

Parameters
valueThe value to write.
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 2271 of file Console.cs.

◆ Write() [15/17]

static void System.Console.Write ( ulong  value)
static

Writes the text representation of the specified 64-bit unsigned integer value to the standard output stream.

Parameters
valueThe value to write.
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 2282 of file Console.cs.

◆ Write() [16/17]

static void System.Console.Write ( object  value)
static

Writes the text representation of the specified object to the standard output stream.

Parameters
valueThe value to write, or null.
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 2292 of file Console.cs.

◆ Write() [17/17]

static void System.Console.Write ( string  value)
static

Writes the specified string value to the standard output stream.

Parameters
valueThe value to write.
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 2302 of file Console.cs.

◆ WriteLine() [1/18]

static void System.Console.WriteLine ( )
static

Writes the current line terminator to the standard output stream.

Exceptions
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 1852 of file Console.cs.

◆ WriteLine() [2/18]

static void System.Console.WriteLine ( bool  value)
static

Writes the text representation of the specified Boolean value, followed by the current line terminator, to the standard output stream.

Parameters
valueThe value to write.
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 1862 of file Console.cs.

◆ WriteLine() [3/18]

static void System.Console.WriteLine ( char  value)
static

Writes the specified Unicode character, followed by the current line terminator, value to the standard output stream.

Parameters
valueThe value to write.
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 1872 of file Console.cs.

◆ WriteLine() [4/18]

static void System.Console.WriteLine ( char []  buffer)
static

Writes the specified array of Unicode characters, followed by the current line terminator, to the standard output stream.

Parameters
bufferA Unicode character array.
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 1882 of file Console.cs.

◆ WriteLine() [5/18]

static void System.Console.WriteLine ( char []  buffer,
int  index,
int  count 
)
static

Writes the specified subarray of Unicode characters, followed by the current line terminator, to the standard output stream.

Parameters
bufferAn array of Unicode characters.
indexThe starting position in buffer .
countThe number of characters to write.
Exceptions
T:System.ArgumentNullExceptionbuffer is null.
T:System.ArgumentOutOfRangeExceptionindex or count is less than zero.
T:System.ArgumentExceptionindex plus count specify a position that is not within buffer .
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 1900 of file Console.cs.

◆ WriteLine() [6/18]

static void System.Console.WriteLine ( decimal  value)
static

Writes the text representation of the specified T:System.Decimal value, followed by the current line terminator, to the standard output stream.

Parameters
valueThe value to write.
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 1910 of file Console.cs.

◆ WriteLine() [7/18]

static void System.Console.WriteLine ( double  value)
static

Writes the text representation of the specified double-precision floating-point value, followed by the current line terminator, to the standard output stream.

Parameters
valueThe value to write.
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 1920 of file Console.cs.

◆ WriteLine() [8/18]

static void System.Console.WriteLine ( float  value)
static

Writes the text representation of the specified single-precision floating-point value, followed by the current line terminator, to the standard output stream.

Parameters
valueThe value to write.
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 1930 of file Console.cs.

◆ WriteLine() [9/18]

static void System.Console.WriteLine ( int  value)
static

Writes the text representation of the specified 32-bit signed integer value, followed by the current line terminator, to the standard output stream.

Parameters
valueThe value to write.
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 1940 of file Console.cs.

◆ WriteLine() [10/18]

static void System.Console.WriteLine ( uint  value)
static

Writes the text representation of the specified 32-bit unsigned integer value, followed by the current line terminator, to the standard output stream.

Parameters
valueThe value to write.
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 1951 of file Console.cs.

◆ WriteLine() [11/18]

static void System.Console.WriteLine ( long  value)
static

Writes the text representation of the specified 64-bit signed integer value, followed by the current line terminator, to the standard output stream.

Parameters
valueThe value to write.
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 1961 of file Console.cs.

◆ WriteLine() [12/18]

static void System.Console.WriteLine ( ulong  value)
static

Writes the text representation of the specified 64-bit unsigned integer value, followed by the current line terminator, to the standard output stream.

Parameters
valueThe value to write.
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 1972 of file Console.cs.

◆ WriteLine() [13/18]

static void System.Console.WriteLine ( object  value)
static

Writes the text representation of the specified object, followed by the current line terminator, to the standard output stream.

Parameters
valueThe value to write.
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 1982 of file Console.cs.

◆ WriteLine() [14/18]

static void System.Console.WriteLine ( string  value)
static

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

Parameters
valueThe value to write.
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 1992 of file Console.cs.

◆ WriteLine() [15/18]

static void System.Console.WriteLine ( string  format,
object  arg0 
)
static

Writes the text representation of the specified object, followed by the current line terminator, to the standard output stream using the specified format information.

Parameters
formatA composite format string (see Remarks).
arg0An object to write using format .
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.
T:System.ArgumentNullExceptionformat is null.
T:System.FormatExceptionThe format specification in format is invalid.

Definition at line 2006 of file Console.cs.

◆ WriteLine() [16/18]

static void System.Console.WriteLine ( string  format,
object  arg0,
object  arg1 
)
static

Writes the text representation of the specified objects, followed by the current line terminator, to the standard output stream using the specified format information.

Parameters
formatA composite format string (see Remarks).
arg0The first object to write using format .
arg1The second object to write using format .
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.
T:System.ArgumentNullExceptionformat is null.
T:System.FormatExceptionThe format specification in format is invalid.

Definition at line 2021 of file Console.cs.

◆ WriteLine() [17/18]

static void System.Console.WriteLine ( string  format,
object  arg0,
object  arg1,
object  arg2 
)
static

Writes the text representation of the specified objects, followed by the current line terminator, to the standard output stream using the specified format information.

Parameters
formatA composite format string (see Remarks).
arg0The first object to write using format .
arg1The second object to write using format .
arg2The third object to write using format .
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.
T:System.ArgumentNullExceptionformat is null.
T:System.FormatExceptionThe format specification in format is invalid.

Definition at line 2037 of file Console.cs.

◆ WriteLine() [18/18]

static void System.Console.WriteLine ( string  format,
params object []  arg 
)
static

Writes the text representation of the specified array of objects, followed by the current line terminator, to the standard output stream using the specified format information.

Parameters
formatA composite format string (see Remarks).
argAn array of objects to write using format .
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.
T:System.ArgumentNullExceptionformat or arg is null.
T:System.FormatExceptionThe format specification in format is invalid.

Definition at line 2070 of file Console.cs.

Property Documentation

◆ BackgroundColor

ConsoleColor System.Console.BackgroundColor
staticgetset

Gets or sets the background color of the console.

Returns
A value that specifies the background color of the console; that is, the color that appears behind each character. The default is black.
Exceptions
T:System.ArgumentExceptionThe color specified in a set operation is not a valid member of T:System.ConsoleColor.
T:System.Security.SecurityExceptionThe user does not have permission to perform this action.
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 463 of file Console.cs.

◆ BufferHeight

int System.Console.BufferHeight
staticgetset

Gets or sets the height of the buffer area.

Returns
The current height, in rows, of the buffer area.
Exceptions
T:System.ArgumentOutOfRangeExceptionThe value in a set operation is less than or equal to zero.-or- The value in a set operation is greater than or equal to F:System.Int16.MaxValue.-or- The value in a set operation is less than P:System.Console.WindowTop + P:System.Console.WindowHeight.
T:System.Security.SecurityExceptionThe user does not have permission to perform this action.
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 535 of file Console.cs.

◆ BufferWidth

int System.Console.BufferWidth
staticgetset

Gets or sets the width of the buffer area.

Returns
The current width, in columns, of the buffer area.
Exceptions
T:System.ArgumentOutOfRangeExceptionThe value in a set operation is less than or equal to zero.-or- The value in a set operation is greater than or equal to F:System.Int16.MaxValue.-or- The value in a set operation is less than P:System.Console.WindowLeft + P:System.Console.WindowWidth.
T:System.Security.SecurityExceptionThe user does not have permission to perform this action.
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 554 of file Console.cs.

◆ CancelKeyPress

ConsoleCancelEventHandler System.Console.CancelKeyPress
staticaddremove

Occurs when the F:System.ConsoleModifiers.Control modifier key (Ctrl) and either the F:System.ConsoleKey.C console key (C) or the Break key are pressed simultaneously (Ctrl+C or Ctrl+Break).

Definition at line 929 of file Console.cs.

◆ CapsLock

bool System.Console.CapsLock
staticget

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

Returns
true if CAPS LOCK is turned on; false if CAPS LOCK is turned off.

Definition at line 878 of file Console.cs.

◆ CursorLeft

int System.Console.CursorLeft
staticgetset

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

Returns
The current position, in columns, of the cursor.
Exceptions
T:System.ArgumentOutOfRangeExceptionThe value in a set operation is less than zero.-or- The value in a set operation is greater than or equal to P:System.Console.BufferWidth.
T:System.Security.SecurityExceptionThe user does not have permission to perform this action.
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 669 of file Console.cs.

◆ CursorSize

int System.Console.CursorSize
staticgetset

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

Returns
The size of the cursor expressed as a percentage of the height of a character cell. The property value ranges from 1 to 100.
Exceptions
T:System.ArgumentOutOfRangeExceptionThe value specified in a set operation is less than 1 or greater than 100.
T:System.Security.SecurityExceptionThe user does not have permission to perform this action.
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 707 of file Console.cs.

◆ CursorTop

int System.Console.CursorTop
staticgetset

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

Returns
The current position, in rows, of the cursor.
Exceptions
T:System.ArgumentOutOfRangeExceptionThe value in a set operation is less than zero.-or- The value in a set operation is greater than or equal to P:System.Console.BufferHeight.
T:System.Security.SecurityExceptionThe user does not have permission to perform this action.
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 688 of file Console.cs.

◆ CursorVisible

bool System.Console.CursorVisible
staticgetset

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

Returns
true if the cursor is visible; otherwise, false.
Exceptions
T:System.Security.SecurityExceptionThe user does not have permission to perform this action.
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 745 of file Console.cs.

◆ Error

TextWriter System.Console.Error
staticget

Gets the standard error output stream.

Returns
A T:System.IO.TextWriter that represents the standard error output stream.

Definition at line 338 of file Console.cs.

◆ ForegroundColor

ConsoleColor System.Console.ForegroundColor
staticgetset

Gets or sets the foreground color of the console.

Returns
A T:System.ConsoleColor that specifies the foreground color of the console; that is, the color of each character that is displayed. The default is gray.
Exceptions
T:System.ArgumentExceptionThe color specified in a set operation is not a valid member of T:System.ConsoleColor.
T:System.Security.SecurityExceptionThe user does not have permission to perform this action.
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 499 of file Console.cs.

◆ In

TextReader System.Console.In
staticget

Gets the standard input stream.

Returns
A T:System.IO.TextReader that represents the standard input stream.

Definition at line 289 of file Console.cs.

◆ InputEncoding

Encoding System.Console.InputEncoding
staticgetset

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

Returns
The encoding used to read console input.
Exceptions
T:System.ArgumentNullExceptionThe property value in a set operation is null.
T:System.IO.IOExceptionAn error occurred during the execution of this operation.
T:System.Security.SecurityExceptionYour application does not have permission to perform this operation.

Definition at line 356 of file Console.cs.

◆ IsErrorRedirected

bool System.Console.IsErrorRedirected
staticget

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

Returns
true if error output is redirected; otherwise, false.

Definition at line 264 of file Console.cs.

◆ IsInputRedirected

bool System.Console.IsInputRedirected
staticget

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

Returns
true if input is redirected; otherwise, false.

Definition at line 214 of file Console.cs.

◆ IsOutputRedirected

bool System.Console.IsOutputRedirected
staticget

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

Returns
true if output is redirected; otherwise, false.

Definition at line 239 of file Console.cs.

◆ KeyAvailable

bool System.Console.KeyAvailable
staticget

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

Returns
true if a key press is available; otherwise, false.
Exceptions
T:System.IO.IOExceptionAn I/O error occurred.
T:System.InvalidOperationExceptionStandard input is redirected to a file instead of the keyboard.

Definition at line 822 of file Console.cs.

◆ LargestWindowHeight

int System.Console.LargestWindowHeight
staticget

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

Returns
The height of the largest possible console window measured in rows.

Definition at line 618 of file Console.cs.

◆ LargestWindowWidth

int System.Console.LargestWindowWidth
staticget

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

Returns
The width of the largest possible console window measured in columns.

Definition at line 606 of file Console.cs.

◆ NumberLock

bool System.Console.NumberLock
staticget

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

Returns
true if NUM LOCK is turned on; false if NUM LOCK is turned off.

Definition at line 865 of file Console.cs.

◆ Out

TextWriter System.Console.Out
staticget

Gets the standard output stream.

Returns
A T:System.IO.TextWriter that represents the standard output stream.

Definition at line 323 of file Console.cs.

◆ OutputEncoding

Encoding System.Console.OutputEncoding
staticgetset

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

Returns
The encoding used to write console output.
Exceptions
T:System.ArgumentNullExceptionThe property value in a set operation is null.
T:System.IO.IOExceptionAn error occurred during the execution of this operation.
T:System.Security.SecurityExceptionYour application does not have permission to perform this operation.

Definition at line 405 of file Console.cs.

◆ Title

string System.Console.Title
staticgetset

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

Returns
The string to be displayed in the title bar of the console. The maximum length of the title string is 24500 characters.
Exceptions
T:System.InvalidOperationExceptionIn a get operation, the retrieved title is longer than 24500 characters.
T:System.ArgumentOutOfRangeExceptionIn a set operation, the specified title is longer than 24500 characters.
T:System.ArgumentNullExceptionIn a set operation, the specified title is null.
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 780 of file Console.cs.

◆ TreatControlCAsInput

bool? System.Console.TreatControlCAsInput
staticgetset

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

Returns
true if Ctrl+C is treated as ordinary input; otherwise, false.
Exceptions
T:System.IO.IOExceptionUnable to get or set the input mode of the console input buffer.

Definition at line 892 of file Console.cs.

◆ WindowHeight

int System.Console.WindowHeight
staticgetset

Gets or sets the height of the console window area.

Returns
The height of the console window measured in rows.
Exceptions
T:System.ArgumentOutOfRangeExceptionThe value of the P:System.Console.WindowWidth property or the value of the P:System.Console.WindowHeight property is less than or equal to 0.-or-The value of the P:System.Console.WindowHeight property plus the value of the P:System.Console.WindowTop property is greater than or equal to F:System.Int16.MaxValue.-or-The value of the P:System.Console.WindowWidth property or the value of the P:System.Console.WindowHeight property is greater than the largest possible window width or height for the current screen resolution and console font.
T:System.IO.IOExceptionError reading or writing information.

Definition at line 572 of file Console.cs.

◆ WindowLeft

int System.Console.WindowLeft
staticgetset

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

Returns
The leftmost console window position measured in columns.
Exceptions
T:System.ArgumentOutOfRangeExceptionIn a set operation, the value to be assigned is less than zero.-or-As a result of the assignment, P:System.Console.WindowLeft plus P:System.Console.WindowWidth would exceed P:System.Console.BufferWidth.
T:System.IO.IOExceptionError reading or writing information.

Definition at line 632 of file Console.cs.

◆ WindowTop

int System.Console.WindowTop
staticgetset

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

Returns
The uppermost console window position measured in rows.
Exceptions
T:System.ArgumentOutOfRangeExceptionIn a set operation, the value to be assigned is less than zero.-or-As a result of the assignment, P:System.Console.WindowTop plus P:System.Console.WindowHeight would exceed P:System.Console.BufferHeight.
T:System.IO.IOExceptionError reading or writing information.

Definition at line 650 of file Console.cs.

◆ WindowWidth

int System.Console.WindowWidth
staticgetset

Gets or sets the width of the console window.

Returns
The width of the console window measured in columns.
Exceptions
T:System.ArgumentOutOfRangeExceptionThe value of the P:System.Console.WindowWidth property or the value of the P:System.Console.WindowHeight property is less than or equal to 0.-or-The value of the P:System.Console.WindowHeight property plus the value of the P:System.Console.WindowTop property is greater than or equal to F:System.Int16.MaxValue.-or-The value of the P:System.Console.WindowWidth property or the value of the P:System.Console.WindowHeight property is greater than the largest possible window width or height for the current screen resolution and console font.
T:System.IO.IOExceptionError reading or writing information.

Definition at line 590 of file Console.cs.


The documentation for this class was generated from the following file: