Skip to Main Content
C# in a Nutshell
book

C# in a Nutshell

by Ben Albahari, Ted Neward, Peter Drayton
March 2002
Intermediate to advanced content levelIntermediate to advanced
864 pages
31h 8m
English
O'Reilly Media, Inc.
Content preview from C# in a Nutshell

Name

Console

Synopsis

The Console class provides static methods that allow you to create console, or command-line, applications. If you attempt to use these methods in a Windows Forms application, they are ignored. For a console application, data is transmitted through three streams. Input is received from the standard input stream, output is written through the standard output stream, and error data is written to the standard error output stream. These streams are provided through the In property, which is a System.IO.TextReader object, and through the Out and Error properties, which are System.IO.TextWriter objects. You can use the methods of these objects directly, or you can use the methods provided by the Console class. For example, you can use the Write() method to write any basic data type to the console window (or use WriteLine() to write data with a trailing hard return). You can also use the ReadLine() method to cause the console window to wait for input. When the user presses the Enter key, this method returns with a string containing the input characters (except the final hard return).

You can use the SetIn(), SetOut(), and SetError() methods to bind the console to different stream objects, such as System.IO.FileStream. To reset the streams to their default objects, use the methods prefixed with OpenStandard.

public sealed class Console {
// Public Static Properties
   public static field TextWriter Error{get; } 
   public static field TextReader In{get; } public static field ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# 8.0 in a Nutshell

C# 8.0 in a Nutshell

Joseph Albahari, Eric Johannsen
C# 10 in a Nutshell

C# 10 in a Nutshell

Joseph Albahari
C# in a Nutshell, Second Edition

C# in a Nutshell, Second Edition

Peter Drayton, Ben Albahari, Ted Neward
Code like a Pro in C#

Code like a Pro in C#

Jort Rodenburg

Publisher Resources

ISBN: 0596001819Catalog PageErrata