asp.net.ph

Console Class

System Namespace


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

Console Class Members

Collapse   Properties

Visibility Name Value Type Accessibility
public static BackgroundColor ConsoleColor [ Get , Set ]
public static BufferHeight Int32 [ Get , Set ]
public static BufferWidth Int32 [ Get , Set ]
public static CapsLock Boolean [ Get ]
public static CursorLeft Int32 [ Get , Set ]
public static CursorSize Int32 [ Get , Set ]
public static CursorTop Int32 [ Get , Set ]
public static CursorVisible Boolean [ Get , Set ]
public static Error TextWriter [ Get ]
public static ForegroundColor ConsoleColor [ Get , Set ]
public static In TextReader [ Get ]
public static InputEncoding Encoding [ Get , Set ]
public static IsErrorRedirected Boolean [ Get ]
public static IsInputRedirected Boolean [ Get ]
public static IsOutputRedirected Boolean [ Get ]
public static KeyAvailable Boolean [ Get ]
public static LargestWindowHeight Int32 [ Get ]
public static LargestWindowWidth Int32 [ Get ]
public static NumberLock Boolean [ Get ]
public static Out TextWriter [ Get ]
public static OutputEncoding Encoding [ Get , Set ]
public static Title String [ Get , Set ]
public static TreatControlCAsInput Boolean [ Get , Set ]
public static WindowHeight Int32 [ Get , Set ]
public static WindowLeft Int32 [ Get , Set ]
public static WindowTop Int32 [ Get , Set ]
public static WindowWidth Int32 [ Get , Set ]

Collapse   Methods

Visibility Name Parameters Return Type
public static Beep ( Int32 frequency , Int32 duration ) Void
public static Beep ( ) Void
public static Clear ( ) Void
public static MoveBufferArea ( Int32 sourceLeft , Int32 sourceTop , Int32 sourceWidth , Int32 sourceHeight , Int32 targetLeft , Int32 targetTop , Char sourceChar , ConsoleColor sourceForeColor , ConsoleColor sourceBackColor ) Void
public static MoveBufferArea ( Int32 sourceLeft , Int32 sourceTop , Int32 sourceWidth , Int32 sourceHeight , Int32 targetLeft , Int32 targetTop ) Void
public static OpenStandardError ( Int32 bufferSize ) Stream
public static OpenStandardError ( ) Stream
public static OpenStandardInput ( Int32 bufferSize ) Stream
public static OpenStandardInput ( ) Stream
public static OpenStandardOutput ( Int32 bufferSize ) Stream
public static OpenStandardOutput ( ) Stream
public static Read ( ) Int32
public static ReadKey ( ) ConsoleKeyInfo
public static ReadKey ( Boolean intercept ) ConsoleKeyInfo
public static ReadLine ( ) String
public static ResetColor ( ) Void
public static SetBufferSize ( Int32 width , Int32 height ) Void
public static SetCursorPosition ( Int32 left , Int32 top ) Void
public static SetError ( TextWriter newError ) Void
public static SetIn ( TextReader newIn ) Void
public static SetOut ( TextWriter newOut ) Void
public static SetWindowPosition ( Int32 left , Int32 top ) Void
public static SetWindowSize ( Int32 width , Int32 height ) Void
public static Write ( Boolean value ) Void
public static Write ( String format , Object arg ) Void
public static Write ( Char buffer ) Void
public static Write ( Char value ) Void
public static Write ( String format , Object arg0 , Object arg1 ) Void
public static Write ( String format , Object arg0 ) Void
public static Write ( String format , Object arg0 , Object arg1 , Object arg2 , Object arg3 ) Void
public static Write ( String format , Object arg0 , Object arg1 , Object arg2 ) Void
public static Write ( Char buffer , Int32 index , Int32 count ) Void
public static Write ( Int64 value ) Void
public static Write ( UInt32 value ) Void
public static Write ( Object value ) Void
public static Write ( UInt64 value ) Void
public static Write ( Decimal value ) Void
public static Write ( Double value ) Void
public static Write ( Int32 value ) Void
public static Write ( Single value ) Void
public static Write ( String value ) Void
public static WriteLine ( Decimal value ) Void
public static WriteLine ( Char buffer , Int32 index , Int32 count ) Void
public static WriteLine ( Single value ) Void
public static WriteLine ( Int32 value ) Void
public static WriteLine ( ) Void
public static WriteLine ( Double value ) Void
public static WriteLine ( Boolean value ) Void
public static WriteLine ( Char buffer ) Void
public static WriteLine ( Char value ) Void
public static WriteLine ( String format , Object arg0 , Object arg1 ) Void
public static WriteLine ( String format , Object arg0 ) Void
public static WriteLine ( String format , Object arg0 , Object arg1 , Object arg2 ) Void
public static WriteLine ( String format , Object arg0 , Object arg1 , Object arg2 , Object arg3 ) Void
public static WriteLine ( String format , Object arg ) Void
public static WriteLine ( Int64 value ) Void
public static WriteLine ( UInt32 value ) Void
public static WriteLine ( UInt64 value ) Void
public static WriteLine ( String value ) Void
public static WriteLine ( Object value ) Void

Collapse   Events

Multicast Name Type
multicast CancelKeyPress ConsoleCancelEventHandler

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 application, writes to the console are not printed 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 In, Out, and Error properties.

By default, the value of the In property is a System.IO.TextReader object, while the values of the Out and Error properties are System.IO.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 contains convenience methods that can 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.

If there is no convenience method in this class that does what you want, you can explicitly invoke the method and property members of the stream objects represented by the In, Out, and Error properties. For example, the convenience method, WriteLine, 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 convenience 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 Out or 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

[ VB, C#, C++ ] 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 SetIn and SetOut methods.

[ VB ]
Public Shared Sub Main ( )
    Response.Write ( "Hola " )
    Response.Write ( "Mundo!" )
    Response.Write ( "What is your name: " )
    Dim name As String = Console.ReadLine ( )
    Response.Write ( "Buenos Dias, " )
    Response.Write ( name )
    Response.Write ( "!" )
End Sub 'Main

[ C# ]
public static void Main ( string [ ] args ) {
    Response.Write ( "Hola " );
    Response.Write ( "Mundo!" );
    Response.Write ( "What is your name: " );
    String name = Console.ReadLine ( );
    Response.Write ( "Buenos Dias, " );
    Response.Write ( name );
    Response.Write ( "!" );
}

[ C++ ]

 void main ( )
 {
   Console::Write ( L"Hola " );
   Console::WriteLine ( L"Mundo!" );
   Console::WriteLine ( L"What is your name: " );
   String *name = Console::ReadLine ( );
   Console::Write ( L"Buenos Dias, " );
   Console::Write ( name );
   Console::WriteLine ( L"!" );
}
Skip Navigation Links



Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph