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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.