Mono Class Library: System Namespace

System.Console Class

Represents the standard input, output, and error streams for console applications. [Edit]

See Also: Console Members

public static class Console

Thread Safety

This type is safe for multithreaded operations.

Remarks

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 Console.SetIn(System.IO.TextReader), Console.SetOut(System.IO.TextWriter), and 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 System.IO.TextReader and System.IO.TextWriter instances. Multiple threads can concurrently read from and/or write to an instance of this type.

[Edit]

Example

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

C# Example
using System;

public class ConsoleTest {
   public static void Main() {       
      Console.Write("Hello ");
      Console.WriteLine("World!");
      Console.Write("What is your name: ");
      string name = Console.ReadLine();
      Console.Write("Hello, ");
      Console.Write(name);
      Console.WriteLine("!");
   }
}

The output for a user who entered the name "Fred" is

Hello World!
What is your name: Fred
Hello, Fred!

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0