System.Console Class

Base Types

Assembly

Library

Summary

Description

The Console
class provides basic input and output support for applications that
read from and write characters to the console. If the console does not exist,
as in a GUI application, writing to the console produces
no result, and no exception is raised.

The standard input, output, and
error streams are represented by properties, and are automatically associated with
the console when the application starts. Applications can redirect these properties to other streams;
for example, streams associated with files instead of the console. [Note: For additional information see the System.Console.SetIn(System.IO.TextReader), System.Console.SetOut(System.IO.TextWriter), and
System.Console.SetError(System.IO.TextWriter) methods.]

By default, the read
methods in this class use the standard input stream and the write methods use
the standard output
stream.

The
write methods support writing data with or without automatically appending carriage
return and linefeed characters. This enables the writing of strings, formatted strings, arrays of characters,
instances of primitive types, and arbitrary objects without first having to convert them
to strings.

This class uses synchronized TextReader and
TextWriter instances. Multiple threads can concurrently read
from and/or write to an instance of this
type.

Example

The following example demonstrates the use of basic Console input and output
functions. The program waits for the user to enter a name.

Return Value

Description

Buffering console streams is not required to be
supported. If it is not supported, the bufferSize parameter is ignored,
and this method behaves identically to System.Console.OpenStandardError(). If buffering is supported, the buffering behavior of
the Console
class is implementation-specific.

Return Value

Description

Buffering console streams is not required to be
supported. If it is not supported, the bufferSize parameter is ignored,
and this method behaves identically to System.Console.OpenStandardInput(). If buffering is supported, the buffering behavior of
the Console
class is implementation-specific.

Return Value

Description

Buffering console streams is not required to be
supported. If it is not supported, the bufferSize parameter is ignored,
and this method behaves identically to System.Console.OpenStandardOutput(). If buffering is supported, the buffering behavior of
the Console
class is implementation-specific.

Exceptions

Description

This method will not return until the read operation is
terminated; for example, by the user pressing the enter key. If data is
available, the input stream contains what the user entered, suffixed with the
environment dependent newline character.

Exceptions

There is insufficient memory to allocate a buffer for the returned string.

Description

A line is defined as a sequence of characters followed
by a carriage return (Unicode 0x000d), a line feed (Unicode 0x000a), or a System.Environment.NewLine. The returned string
does not contain the terminating character(s).

Parameters

Exceptions

Description

This version of System.Console.Write(System.String,System.Object) is equivalent to System.Console.Out.Write
(
value.ToString () ).

[Note: If value is null
, no exception is thrown and nothing
is written. Otherwise, the object's System.Object.ToString method is called to
produce the string representation, and the resulting string is written to the
output stream.]