TextReader and TextWriter

The two classes we briefly encountered in the previous examples are subclasses of the TextReader and TextWriter classes. Using object-oriented programming at its best, these base classes offer virtual methods for a series of operations that can be applied in more than just the context of file I/O. In fact, on our much beloved Console class, you can find static properties called In and Out that expose a TextReader and a TextWriter:

string line = Console.In.ReadLine();Console.Out.WriteLine(line);

Console directly offers access to those common operations by providing shortcut methods on the class itself, but in reality a pair of reader and writer objects provides access to the Win32 console. ...

Get C# 5.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.