System.Console Class

Assembly: Mscorlib.dll
Namespace: System
Summary
Represents the standard input, output, and error streams for console applications. This class cannot be inherited.
C# Syntax:
public sealed class Console
Thread Safety
This type is safe for multithreaded operations.
Remarks
The Console class provides basic support for applications that read characters from, and write characters to, the console. If the console does not exist, as in a Windows-based application, writes to the console are not displayed and no exception is raised.

Data from the console is read from the standard input stream; normal data to the console is written to the standard output stream; and error data to the console is written to the standard error output stream. These streams are automatically associated with the console when your application starts, and are presented to you as the Console.In, Console.Out, and Console.Error properties.

By default, the value of the Console.In property is a TextReader, while the values of the Console.Out and Console.Error properties are TextWriter objects. However, you can associate these properties with streams that do not represent the console; for example, you can associate them with streams that represent files. You can also associate these properties with different streams at the same time.

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

This class contains methods that read individual characters or entire lines from the console. This class also contains several write methods that automatically convert individual instances of value types, arrays of characters, or sets of objects to a formatted or unformatted string, then writes that string to the console, optionally followed by a line termination string.

You can also explicitly invoke the method and property members of the stream objects represented by the Console.In, Console.Out, and Console.Error properties. For example, the Console.WriteLine method writes data to the standard output stream followed by a line termination string; that is, data followed by a carriage return and line feed ("\r\n"). However, there is no convenient method to write data to the standard error output stream. Instead, use an explicit invocation like the C# statement, Console.Error.WriteLine(); .

To continue the previous example, the default value of the line termination string is a carriage return followed by a line feed. Change the line termination character sequence by setting the TextWriter.NewLine property of the Console.Out or Console.Error property to another string. For example, the C# statement, Console.Error.NewLine = "\r\n\r\n"; , sets the line termination character sequence for the Console.Error.WriteLine method to two carriage return and line feed sequences.

Example
This code sample demonstrates how to read from and write to the standard input and output streams. Note that these streams can be redirected using the Console.SetIn and Console.SetOut methods.
    public static void Main(string[] args) {
        Console.Write("Hola ");
        Console.WriteLine("Mundo!");
        Console.WriteLine("What is your name: ");
        String name = Console.ReadLine();
        Console.Write("Buenos Dias, ");
        Console.Write(name);
        Console.WriteLine("!");
    }

    
See also:
System Namespace

System.Console Member List:

Public Properties
Error Read-only

Gets the standard error output stream.
In Read-only

Out Read-only

Gets the standard output stream.
Public Methods
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
OpenStandardError Overloaded:
OpenStandardError()

Acquires the standard error stream.
OpenStandardError Overloaded:
OpenStandardError(int bufferSize)

Acquires the standard error stream, set to a specified buffer size.
OpenStandardInput Overloaded:
OpenStandardInput()

Acquires the standard input stream.
OpenStandardInput Overloaded:
OpenStandardInput(int bufferSize)

Acquires the standard input stream, set to a specified buffer size.
OpenStandardOutput Overloaded:
OpenStandardOutput()

Acquires the standard output stream.
OpenStandardOutput Overloaded:
OpenStandardOutput(int bufferSize)

Acquires the standard output stream, set to a specified buffer size.
Read Reads the next character from the standard input stream.
ReadLine Reads the next line of characters from the standard input stream.
SetError Sets the Console.Error property to the specified TextWriter.
SetIn Sets the Console.In property to the specified TextReader.
SetOut Sets the Console.Out property to the specified TextWriter.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Write Overloaded:
Write(bool value)

Writes the text representation of the specified Boolean value to the standard output stream.
Write Overloaded:
Write(char value)

Writes the specified Unicode character value to the standard output stream.
Write Overloaded:
Write(char[] buffer)

Writes the specified array of Unicode characters to the standard output stream.
Write Overloaded:
Write(decimal value)

Writes the text representation of the specified Decimal value to the standard output stream.
Write Overloaded:
Write(double value)

Writes the text representation of the specified double-precision floating-point value to the standard output stream.
Write Overloaded:
Write(int value)

Writes the text representation of the specified 32-bit signed integer value to the standard output stream.
Write Overloaded:
Write(long value)

Writes the text representation of the specified 64-bit signed integer value to the standard output stream.
Write Overloaded:
Write(object value)

Writes the text representation of the specified object to the standard output stream.
Write Overloaded:
Write(float value)

Writes the text representation of the specified single-precision floating-point value to the standard output stream.
Write Overloaded:
Write(string value)

Writes the specified string value to the standard output stream.
Write Overloaded:
Write(uint value)

Writes the text representation of the specified 32-bit unsigned integer value to the standard output stream.
Write Overloaded:
Write(ulong value)

Writes the text representation of the specified 64-bit unsigned integer value to the standard output stream.
Write Overloaded:
Write(string format, object arg0)

Writes the specified object to the standard output stream using the specified format information.
Write Overloaded:
Write(string format, params object[] arg)

Writes the specified array of objects to the standard output stream using the specified format information.
Write Overloaded:
Write(char[] buffer, int index, int count)

Writes the specified subarray of Unicode characters to the standard output stream.
Write Overloaded:
Write(string format, object arg0, object arg1)

Writes the specified objects to the standard output stream using the specified format information.
Write Overloaded:
Write(string format, object arg0, object arg1, object arg2)

Writes the specified objects to the standard output stream using the specified format information.
Write Overloaded:
Write

Writes the specified objects and variable length parameter list to the standard output stream using the specified format information.
WriteLine Overloaded:
WriteLine()

Writes the current line terminator to the standard output stream.
WriteLine Overloaded:
WriteLine(bool value)

Writes the text representation of the specified Boolean value, followed by the current line terminator, to the standard output stream.
WriteLine Overloaded:
WriteLine(char value)

Writes the specified Unicode character, followed by the current line terminator, value to the standard output stream.
WriteLine Overloaded:
WriteLine(char[] buffer)

Writes the specified array of Unicode characters, followed by the current line terminator, to the standard output stream.
WriteLine Overloaded:
WriteLine(decimal value)

Writes the text representation of the specified Decimal value, followed by the current line terminator, to the standard output stream.
WriteLine Overloaded:
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.
WriteLine Overloaded:
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.
WriteLine Overloaded:
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.
WriteLine Overloaded:
WriteLine(object value)

Writes the text representation of the specified object, followed by the current line terminator, to the standard output stream.
WriteLine Overloaded:
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.
WriteLine Overloaded:
WriteLine(string value)

Writes the specified string value, followed by the current line terminator, to the standard output stream.
WriteLine Overloaded:
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.
WriteLine Overloaded:
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.
WriteLine Overloaded:
WriteLine(string format, object arg0)

Writes the specified object, followed by the current line terminator, to the standard output stream using the specified format information.
WriteLine Overloaded:
WriteLine(string format, params object[] arg)

Writes the specified array of objects, followed by the current line terminator, to the standard output stream using the specified format information.
WriteLine Overloaded:
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.
WriteLine Overloaded:
WriteLine(string format, object arg0, object arg1)

Writes the specified objects, followed by the current line terminator, to the standard output stream using the specified format information.
WriteLine Overloaded:
WriteLine(string format, object arg0, object arg1, object arg2)

Writes the specified objects, followed by the current line terminator, to the standard output stream using the specified format information.
WriteLine Overloaded:
WriteLine

Writes the specified objects and variable length parameter list, followed by the current line terminator, to the standard output stream using the specified format information.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Console Member Details

Property: Error (read-only)
Summary
Gets the standard error output stream.
C# Syntax:
public static TextWriter Error {get;}
Remarks
This property is set to the standard error stream by default. This property can be set to another stream with the Console.SetError method.
See also:
Console.In | Console.Out | Console.SetError

Return to top


Property: In (read-only)
Summary
Gets the standard input stream.
C# Syntax:
public static TextReader In {get;}
Remarks
This property is set to the standard input stream by default. This property can be set to another stream with the Console.SetIn method.
See also:
Console.Error | Console.Out | Console.SetIn

Return to top


Property: Out (read-only)
Summary
Gets the standard output stream.
C# Syntax:
public static TextWriter Out {get;}
Remarks
This property is set to the standard output stream by default. This property can be set to another stream with the Console.SetOut method.
See also:
Console.Error | Console.In | Console.SetOut

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~Console();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: OpenStandardError()
Summary
Acquires the standard error stream.
C# Syntax:
public static Stream OpenStandardError();
Return Value:
The standard error stream.
Remarks
This method can be used to reacquire the standard error stream after it has been changed by the Console.SetError method.
See also:
Console.Error | Console.SetError

Return to top


Overloaded Method: OpenStandardError(
   int bufferSize
)
Summary
Acquires the standard error stream, set to a specified buffer size.
C# Syntax:
public static Stream OpenStandardError(
   int bufferSize
);
Parameters:

bufferSize

The internal stream buffer size.

Return Value:
The standard error stream.
Exceptions
Exception Type Condition
ArgumentOutOfRangeException bufferSize is less than or equal to zero.
Remarks
This method can be used to reacquire the standard error stream after it has been changed by the Console.SetError method.
See also:
Console.Error | Console.SetError

Return to top


Overloaded Method: OpenStandardInput()
Summary
Acquires the standard input stream.
C# Syntax:
public static Stream OpenStandardInput();
Return Value:
The standard input stream.
Remarks
This method can be used to reacquire the standard input stream after it has been changed by the Console.SetIn method.
See also:
Console.In | Console.SetIn

Return to top


Overloaded Method: OpenStandardInput(
   int bufferSize
)
Summary
Acquires the standard input stream, set to a specified buffer size.
C# Syntax:
public static Stream OpenStandardInput(
   int bufferSize
);
Parameters:

bufferSize

The internal stream buffer size.

Return Value:
The standard input stream.
Exceptions
Exception Type Condition
ArgumentOutOfRangeException bufferSize is less than or equal to zero.
Remarks
This method can be used to reacquire the standard output stream after it has been changed by the Console.SetIn method.
See also:
Console.In | Console.SetIn

Return to top


Overloaded Method: OpenStandardOutput()
Summary
Acquires the standard output stream.
C# Syntax:
public static Stream OpenStandardOutput();
Return Value:
The standard output stream.
Remarks
This method can be used to reacquire the standard output stream after it has been changed by the Console.SetOut method.
See also:
Console.Out | Console.SetOut

Return to top


Overloaded Method: OpenStandardOutput(
   int bufferSize
)
Summary
Acquires the standard output stream, set to a specified buffer size.
C# Syntax:
public static Stream OpenStandardOutput(
   int bufferSize
);
Parameters:

bufferSize

The internal stream buffer size.

Return Value:
The standard output stream.
Exceptions
Exception Type Condition
ArgumentOutOfRangeException bufferSize is less than or equal to zero.
Remarks
This method can be used to reacquire the standard output stream after it has been changed by the Console.SetOut method.
See also:
Console.Out | Console.SetOut

Return to top


Method: Read()
Summary
Reads the next character from the standard input stream.
C# Syntax:
public static int Read();
Return Value:
The next character from the input stream, or negative one (-1) if no more characters are available.
Exceptions
Exception Type Condition
IOException An I/O error occurred.
Remarks
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.
Example
     int i;
     char c;
     while (true)
     {
      i = Console.Read ();
      if (i == -1) break;
      c = (char) i;
      Console.WriteLine ("Echo: {0}", c);
     }
     Console.WriteLine ("Done");
     return 0;

    
See also:
Console.ReadLine | Console.Write | Console.WriteLine

Return to top


Method: ReadLine()
Summary
Reads the next line of characters from the standard input stream.
C# Syntax:
public static string ReadLine();
Return Value:
The next line from the input stream, or null if no more characters are available.
Exceptions
Exception Type Condition
IOException An I/O error occurred.
OutOfMemoryException There is insufficient memory to allocate a buffer for the returned string.
Remarks
A line is defined as a sequence of characters followed by a carriage return (hexadecimal 0x000d), a line feed (hexadecimal 0x000a), or Environment.NewLine. The returned string does not contain the terminating character(s).

If this method throws OutOfMemoryException, the reader's position in the underlying Stream is advanced by the number of characters the method was able to read, but the characters already read into the internal Console.ReadLine buffer are discarded. Since the position of the reader in the stream cannot be changed, the characters already read are unrecoverable, and can be accessed only by reinitializing the TextReader. If the initial position within the stream is unknown or the stream does not support seeking, the underlying Stream also needs to be reinitialized.

To avoid such a situation and produce robust code you should use the Console.Read method and store the read characters in a preallocated buffer.

See also:
Console.Read | Console.Write | Console.WriteLine

Return to top


Method: SetError(
   TextWriter newError
)
Summary
Sets the Console.Error property to the specified TextWriter.
C# Syntax:
public static void SetError(
   TextWriter newError
);
Parameters:

newError

A TextWriter stream that is the new standard error output.

Exceptions
Exception Type Condition
ArgumentNullException newError is null.
Remarks
By default, the Console.Error property is set to the standard error output stream.

A StreamWriter that encapsulates a FileStream can be used to send error messages to a file.

.NET Framework Security:
SecurityPermissionFlag for calling unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode
See also:
TextWriter | Console.Error

Return to top


Method: SetIn(
   TextReader newIn
)
Summary
Sets the Console.In property to the specified TextReader.
C# Syntax:
public static void SetIn(
   TextReader newIn
);
Parameters:

newIn

A TextReader stream that is the new standard input.

Exceptions
Exception Type Condition
ArgumentNullException newIn is null.
Remarks
By default, the Console.In property is set to the standard input stream.

A StreamReader that encapsulates a FileStream can be used to receive input from a file.

.NET Framework Security:
SecurityPermissionFlag for calling unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode
See also:
TextReader | Console.In

Return to top


Method: SetOut(
   TextWriter newOut
)
Summary
Sets the Console.Out property to the specified TextWriter.
C# Syntax:
public static void SetOut(
   TextWriter newOut
);
Parameters:

newOut

A TextWriter stream that is the new standard output.

Exceptions
Exception Type Condition
ArgumentNullException newOut is null.
Remarks
By default, the Console.Out property is set to the standard output stream.

A StreamWriter that encapsulates a FileStream can be used to send output to a file. For example:

              Console.WriteLine("Hello World");
               FileStream fs1 = new FileStream("Test.txt", FileMode.Create);
               // First, save the standard output.
               TextWriter tmp = Console.Out;
               
               StreamWriter sw1 = new StreamWriter(fs1);
               Console.SetOut(sw1);
               Console.WriteLine("Hello file");
               
               Console.SetOut(tmp);
               Console.WriteLine("Hello World");
               
               sw1.Close();
            
.NET Framework Security:
SecurityPermissionFlag for calling unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode
See also:
TextWriter | Console.Out

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: Write(
   bool value
)
Summary
Writes the text representation of the specified Boolean value to the standard output stream.
C# Syntax:
public static void Write(
   bool value
);
Parameters:

value

The value to write.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
Remarks
The text representation of value is produced by calling Boolean.ToString, which outputs either Boolean.TrueString or Boolean.FalseString.
See also:
Console.Read | Console.ReadLine | Console.WriteLine

Return to top


Overloaded Method: Write(
   char value
)
Summary
Writes the specified Unicode character value to the standard output stream.
C# Syntax:
public static void Write(
   char value
);
Parameters:

value

The value to write.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
See also:
Console.Read | Console.ReadLine | Console.WriteLine

Return to top


Overloaded Method: Write(
   char[] buffer
)
Summary
Writes the specified array of Unicode characters to the standard output stream.
C# Syntax:
public static void Write(
   char[] buffer
);
Parameters:

buffer

A Unicode character array.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
See also:
Console.Read | Console.ReadLine | Console.WriteLine

Return to top


Overloaded Method: Write(
   decimal value
)
Summary
Writes the text representation of the specified Decimal value to the standard output stream.
C# Syntax:
public static void Write(
   decimal value
);
Parameters:

value

The value to write.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
Remarks
The text representation of value is produced by calling Decimal.ToString.
See also:
Console.Read | Console.ReadLine | Console.WriteLine

Return to top


Overloaded Method: Write(
   double value
)
Summary
Writes the text representation of the specified double-precision floating-point value to the standard output stream.
C# Syntax:
public static void Write(
   double value
);
Parameters:

value

The value to write.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
Remarks
The text representation of value is produced by calling Double.ToString.
See also:
Console.Read | Console.ReadLine | Console.WriteLine

Return to top


Overloaded Method: Write(
   int value
)
Summary
Writes the text representation of the specified 32-bit signed integer value to the standard output stream.
C# Syntax:
public static void Write(
   int value
);
Parameters:

value

The value to write.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
Remarks
The text representation of value is produced by calling Int32.ToString.
See also:
Console.Read | Console.ReadLine | Console.WriteLine

Return to top


Overloaded Method: Write(
   long value
)
Summary
Writes the text representation of the specified 64-bit signed integer value to the standard output stream.
C# Syntax:
public static void Write(
   long value
);
Parameters:

value

The value to write.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
Remarks
The text representation of value is produced by calling Int64.ToString.
See also:
Console.Read | Console.ReadLine | Console.WriteLine

Return to top


Overloaded Method: Write(
   object value
)
Summary
Writes the text representation of the specified object to the standard output stream.
C# Syntax:
public static void Write(
   object value
);
Parameters:

value

The value to write, or null.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
Remarks
If value is null, nothing is written and no exception is thrown. Otherwise, the ToString method of value is called to produce its string representation, and the resulting string is written to the standard output stream.
See also:
Console.Read | Console.ReadLine | Console.WriteLine

Return to top


Overloaded Method: Write(
   float value
)
Summary
Writes the text representation of the specified single-precision floating-point value to the standard output stream.
C# Syntax:
public static void Write(
   float value
);
Parameters:

value

The value to write.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
Remarks
The text representation of value is produced by calling Single.ToString.
See also:
Console.Read | Console.ReadLine | Console.WriteLine

Return to top


Overloaded Method: Write(
   string value
)
Summary
Writes the specified string value to the standard output stream.
C# Syntax:
public static void Write(
   string value
);
Parameters:

value

The value to write.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
Remarks
If value is null, nothing is written to the standard output stream.
See also:
Console.Read | Console.ReadLine | Console.WriteLine

Return to top


Overloaded Method: Write(
   uint value
)
Summary
Writes the text representation of the specified 32-bit unsigned integer value to the standard output stream.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public static void Write(
   uint value
);
Parameters:

value

The value to write.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
Remarks
The text representation of value is produced by calling UInt32.ToString.
See also:
Console.Read | Console.ReadLine | Console.WriteLine

Return to top


Overloaded Method: Write(
   ulong value
)
Summary
Writes the text representation of the specified 64-bit unsigned integer value to the standard output stream.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public static void Write(
   ulong value
);
Parameters:

value

The value to write.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
Remarks
The text representation of value is produced by calling UInt64.ToString.
See also:
Console.Read | Console.ReadLine | Console.WriteLine

Return to top


Overloaded Method: Write(
   string format,
   object arg0
)
Summary
Writes the specified object to the standard output stream using the specified format information.
C# Syntax:
public static void Write(
   string format,
   object arg0
);
Parameters:

format

The format string.

arg0

Object to write using format.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
ArgumentNullException format or any of the object parameters is null.
FormatException The format specification in format is invalid.
Remarks
This method uses the same semantics as String.Format.

If a parameter object is not referenced in format, it is ignored.

See also:
MSDN: formattingoverview | Console.Read | Console.ReadLine | Console.WriteLine

Return to top


Overloaded Method: Write(
   string format,
   params object[] arg
)
Summary
Writes the specified array of objects to the standard output stream using the specified format information.
C# Syntax:
public static void Write(
   string format,
   params object[] arg
);
Parameters:

format

The format string.

arg

An array of objects to write using format.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
ArgumentNullException format or any of the object parameters is null.
FormatException The format specification in format is invalid.
Remarks
This method uses the same semantics as String.Format.

If a parameter object is not referenced in format, it is ignored.

See also:
MSDN: formattingoverview | Console.Read | Console.ReadLine | Console.WriteLine

Return to top


Overloaded Method: Write(
   char[] buffer,
   int index,
   int count
)
Summary
Writes the specified subarray of Unicode characters to the standard output stream.
C# Syntax:
public static void Write(
   char[] buffer,
   int index,
   int count
);
Parameters:

buffer

An array of Unicode characters.

index

The starting position in buffer.

count

The number of characters to write.

Exceptions
Exception Type Condition
ArgumentNullException buffer is null.
ArgumentOutOfRangeException index or count is less than zero.
ArgumentException index plus count specify a position that is not within buffer.
IOException An I/O error occurred.
Remarks
This method writes count characters starting at position index of buffer to the standard output stream.
See also:
Console.Read | Console.ReadLine | Console.WriteLine

Return to top


Overloaded Method: Write(
   string format,
   object arg0,
   object arg1
)
Summary
Writes the specified objects to the standard output stream using the specified format information.
C# Syntax:
public static void Write(
   string format,
   object arg0,
   object arg1
);
Parameters:

format

The format string.

arg0

The first object to write using format.

arg1

The second object to write using format.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
ArgumentNullException format or any of the object parameters is null.
FormatException The format specification in format is invalid.
Remarks
This method uses the same semantics as String.Format.

If a parameter object is not referenced in format, it is ignored.

See also:
MSDN: formattingoverview | Console.Read | Console.ReadLine | Console.WriteLine

Return to top


Overloaded Method: Write(
   string format,
   object arg0,
   object arg1,
   object arg2
)
Summary
Writes the specified objects to the standard output stream using the specified format information.
C# Syntax:
public static void Write(
   string format,
   object arg0,
   object arg1,
   object arg2
);
Parameters:

format

The format string.

arg0

The first object to write using format.

arg1

The second object to write using format.

arg2

The third object to write using format.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
ArgumentNullException format or any of the object parameters is null.
FormatException The format specification in format is invalid.
Remarks
This method uses the same semantics as String.Format.

If a parameter object is not referenced in format, it is ignored.

See also:
MSDN: formattingoverview | Console.Read | Console.ReadLine | Console.WriteLine

Return to top


Overloaded Method: Write
Summary
Writes the specified objects and variable length parameter list to the standard output stream using the specified format information.
Parameters:

format

The format string.

arg0

The first object to write using format.

arg1

The second object to write using format.

arg2

The third object to write using format.

arg3

The fourth object to write using format.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
ArgumentNullException format or any of the object parameters is null.
FormatException The format specification in format is invalid.
Remarks
This method uses the same semantics as String.Format.

If a parameter object is not referenced in format, it is ignored.

See also:
MSDN: formattingoverview | Console.Read | Console.ReadLine | Console.WriteLine

Return to top


Overloaded Method: WriteLine()
Summary
Writes the current line terminator to the standard output stream.
C# Syntax:
public static void WriteLine();
Exceptions
Exception Type Condition
IOException An I/O error occurred.
Remarks
The default line terminator is a string whose value is a carriage return followed by a line feed ("\r\n"). Change the line terminator by setting the TextWriter.NewLine property of the Console.Out property to another string.

For example, in C#, set the line terminator to two carriage return and line feed sequences with the statement, Console.Out.NewLine = "\r\n\r\n"; .

See also:
Console.Read | Console.ReadLine | Console.Write | TextWriter.NewLine | Console.Out

Return to top


Overloaded Method: WriteLine(
   bool value
)
Summary
Writes the text representation of the specified Boolean value, followed by the current line terminator, to the standard output stream.
C# Syntax:
public static void WriteLine(
   bool value
);
Parameters:

value

The value to write.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
Remarks
The text representation of value is produced by calling Boolean.ToString.

For more information about the line terminator, see the Remarks section of the Console.WriteLine method that takes no parameters.

See also:
Console.Read | Console.ReadLine | Console.Write

Return to top


Overloaded Method: WriteLine(
   char value
)
Summary
Writes the specified Unicode character, followed by the current line terminator, value to the standard output stream.
C# Syntax:
public static void WriteLine(
   char value
);
Parameters:

value

The value to write.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
Remarks
For more information about the line terminator, see the Remarks section of the Console.WriteLine method that takes no parameters.
See also:
Console.Read | Console.ReadLine | Console.Write

Return to top


Overloaded Method: WriteLine(
   char[] buffer
)
Summary
Writes the specified array of Unicode characters, followed by the current line terminator, to the standard output stream.
C# Syntax:
public static void WriteLine(
   char[] buffer
);
Parameters:

buffer

A Unicode character array.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
Remarks
For more information about the line terminator, see the Remarks section of the Console.WriteLine method that takes no parameters.
See also:
Console.Read | Console.ReadLine | Console.Write

Return to top


Overloaded Method: WriteLine(
   decimal value
)
Summary
Writes the text representation of the specified Decimal value, followed by the current line terminator, to the standard output stream.
C# Syntax:
public static void WriteLine(
   decimal value
);
Parameters:

value

The value to write.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
Remarks
The text representation of value is produced by calling Decimal.ToString.

For more information about the line terminator, see the Remarks section of the Console.WriteLine method that takes no parameters.

See also:
Console.Read | Console.ReadLine | Console.Write

Return to top


Overloaded Method: WriteLine(
   double value
)
Summary
Writes the text representation of the specified double-precision floating-point value, followed by the current line terminator, to the standard output stream.
C# Syntax:
public static void WriteLine(
   double value
);
Parameters:

value

The value to write.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
Remarks
The text representation of value is produced by calling Double.ToString.

For more information about the line terminator, see the Remarks section of the Console.WriteLine method that takes no parameters.

See also:
Console.Read | Console.ReadLine | Console.Write

Return to top


Overloaded Method: WriteLine(
   int value
)
Summary
Writes the text representation of the specified 32-bit signed integer value, followed by the current line terminator, to the standard output stream.
C# Syntax:
public static void WriteLine(
   int value
);
Parameters:

value

The value to write.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
Remarks
The text representation of value is produced by calling Int32.ToString.

For more information about the line terminator, see the Remarks section of the Console.WriteLine method that takes no parameters.

See also:
Console.Read | Console.ReadLine | Console.Write

Return to top


Overloaded Method: WriteLine(
   long value
)
Summary
Writes the text representation of the specified 64-bit signed integer value, followed by the current line terminator, to the standard output stream.
C# Syntax:
public static void WriteLine(
   long value
);
Parameters:

value

The value to write.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
Remarks
The text representation of value is produced by calling Int64.ToString.

For more information about the line terminator, see the Remarks section of the Console.WriteLine method that takes no parameters.

See also:
Console.Read | Console.ReadLine | Console.Write

Return to top


Overloaded Method: WriteLine(
   object value
)
Summary
Writes the text representation of the specified object, followed by the current line terminator, to the standard output stream.
C# Syntax:
public static void WriteLine(
   object value
);
Parameters:

value

The value to write.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
Remarks
If value is null, nothing is written and no exception is thrown. Otherwise, the ToString method of value is called to produce its string representation, and the resulting string is written to the standard output stream.

For more information about the line terminator, see the Remarks section of the Console.WriteLine method that takes no parameters.

See also:
Console.Read | Console.ReadLine | Console.Write

Return to top


Overloaded Method: WriteLine(
   float value
)
Summary
Writes the text representation of the specified single-precision floating-point value, followed by the current line terminator, to the standard output stream.
C# Syntax:
public static void WriteLine(
   float value
);
Parameters:

value

The value to write.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
Remarks
The text representation of value is produced by calling Single.ToString.

For more information about the line terminator, see the Remarks section of the Console.WriteLine method that takes no parameters.

See also:
Console.Read | Console.ReadLine | Console.Write

Return to top


Overloaded Method: WriteLine(
   string value
)
Summary
Writes the specified string value, followed by the current line terminator, to the standard output stream.
C# Syntax:
public static void WriteLine(
   string value
);
Parameters:

value

The value to write.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
Remarks
If value is null, nothing is written to the standard output stream.

For more information about the line terminator, see the Remarks section of the Console.WriteLine method that takes no parameters.

See also:
Console.Read | Console.ReadLine | Console.Write

Return to top


Overloaded Method: WriteLine(
   uint value
)
Summary
Writes the text representation of the specified 32-bit unsigned integer value, followed by the current line terminator, to the standard output stream.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public static void WriteLine(
   uint value
);
Parameters:

value

The value to write.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
Remarks
The text representation of value is produced by calling UInt32.ToString.

For more information about the line terminator, see the Remarks section of the Console.WriteLine method that takes no parameters.

See also:
Console.Read | Console.ReadLine | Console.Write

Return to top


Overloaded Method: WriteLine(
   ulong value
)
Summary
Writes the text representation of the specified 64-bit unsigned integer value, followed by the current line terminator, to the standard output stream.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public static void WriteLine(
   ulong value
);
Parameters:

value

The value to write.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
Remarks
The text representation of value is produced by calling UInt64.ToString.

For more information about the line terminator, see the Remarks section of the Console.WriteLine method that takes no parameters.

See also:
Console.Read | Console.ReadLine | Console.Write

Return to top


Overloaded Method: WriteLine(
   string format,
   object arg0
)
Summary
Writes the specified object, followed by the current line terminator, to the standard output stream using the specified format information.
C# Syntax:
public static void WriteLine(
   string format,
   object arg0
);
Parameters:

format

The format string.

arg0

Object to write using format.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
ArgumentNullException format or any of the object parameters is null.
FormatException The format specification in format is invalid.
Remarks
This method uses the same semantics as String.Format.

If a parameter object is not referenced in format, it is ignored.

For more information about the line terminator, see the Remarks section of the Console.WriteLine method that takes no parameters.

See also:
MSDN: formattingoverview | Console.Read | Console.ReadLine | Console.Write

Return to top


Overloaded Method: WriteLine(
   string format,
   params object[] arg
)
Summary
Writes the specified array of objects, followed by the current line terminator, to the standard output stream using the specified format information.
C# Syntax:
public static void WriteLine(
   string format,
   params object[] arg
);
Parameters:

format

The format string.

arg

An array of objects to write using format.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
ArgumentNullException format or any of the object parameters is null.
FormatException The format specification in format is invalid.
Remarks
This method uses the same semantics as String.Format.

If a parameter object is not referenced in format, it is ignored.

For more information about the line terminator, see the Remarks section of the Console.WriteLine method that takes no parameters.

See also:
MSDN: formattingoverview | Console.Read | Console.ReadLine | Console.Write

Return to top


Overloaded Method: WriteLine(
   char[] buffer,
   int index,
   int count
)
Summary
Writes the specified subarray of Unicode characters, followed by the current line terminator, to the standard output stream.
C# Syntax:
public static void WriteLine(
   char[] buffer,
   int index,
   int count
);
Parameters:

buffer

An array of Unicode characters.

index

The starting position in buffer.

count

The number of characters to write.

Exceptions
Exception Type Condition
ArgumentNullException buffer is null.
ArgumentOutOfRangeException index or count is less than zero.
ArgumentException index plus count specify a position that is not within buffer.
IOException An I/O error occurred.
Remarks
This method writes count characters starting at position index of buffer to the standard output stream.

For more information about the line terminator, see the Remarks section of the Console.WriteLine method that takes no parameters.

See also:
Console.Read | Console.ReadLine | Console.Write

Return to top


Overloaded Method: WriteLine(
   string format,
   object arg0,
   object arg1
)
Summary
Writes the specified objects, followed by the current line terminator, to the standard output stream using the specified format information.
C# Syntax:
public static void WriteLine(
   string format,
   object arg0,
   object arg1
);
Parameters:

format

The format string.

arg0

The first object to write using format.

arg1

The second object to write using format.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
ArgumentNullException format or any of the object parameters is null.
FormatException The format specification in format is invalid.
Remarks
This method uses the same semantics as String.Format.

If a parameter object is not referenced in format, it is ignored.

For more information about the line terminator, see the Remarks section of the Console.WriteLine method that takes no parameters.

See also:
MSDN: formattingoverview | Console.Read | Console.ReadLine | Console.Write

Return to top


Overloaded Method: WriteLine(
   string format,
   object arg0,
   object arg1,
   object arg2
)
Summary
Writes the specified objects, followed by the current line terminator, to the standard output stream using the specified format information.
C# Syntax:
public static void WriteLine(
   string format,
   object arg0,
   object arg1,
   object arg2
);
Parameters:

format

The format string.

arg0

The first object to write using format.

arg1

The second object to write using format.

arg2

The third object to write using format.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
ArgumentNullException format or any of the object parameters is null.
FormatException The format specification in format is invalid.
Remarks
This method uses the same semantics as String.Format.

If a parameter object is not referenced in format, it is ignored.

For more information about the line terminator, see the Remarks section of the Console.WriteLine method that takes no parameters.

See also:
MSDN: formattingoverview | Console.Read | Console.ReadLine | Console.Write

Return to top


Overloaded Method: WriteLine
Summary
Writes the specified objects and variable length parameter list, followed by the current line terminator, to the standard output stream using the specified format information.
Parameters:

format

The format string.

arg0

The first object to write using format.

arg1

The second object to write using format.

arg2

The third object to write using format.

arg3

The fourth object to write using format.

Exceptions
Exception Type Condition
IOException An I/O error occurred.
ArgumentNullException format or any of the object parameters is null.
FormatException The format specification in format is invalid.
Remarks
This method uses the same semantics as String.Format.

If a parameter object is not referenced in format, it is ignored.

For more information about the line terminator, see the Remarks section of the Console.WriteLine method that takes no parameters.

See also:
MSDN: formattingoverview | Console.Read | Console.ReadLine | Console.Write

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.