The Console Object in C#

 

In the bad old days of computing before visual interfaces like Windows, all interaction with a computer was done through a plain text screen. The combination of the text screen and the keyboards is usually referred to as the console. Although programming on the console might seem kind of old−fashioned, it’s a good place to start because programs which feature the console are easier to write than the fancier programs using Windows forms. In C#, everything is an object, so you’ll work with the console by working with a special object, also called the Console. Note that the names of classes are capitalized, so when I’m referring to the actual Console, class, I use a capital C. Most of your early programs will be built using the Console object, so taking a look at how C# sees this object is a good idea. If you remember working in DOS or command−line UNIX, you probably have some fond memories of the console. Most console applications use only text and appear only in black and white. Modern programs for end users don’t usually work with the console because it makes things much more difficult for users who prefer menus, buttons, and toolbars. However, knowing how to program on the console is still useful because some applications don’t require a graphic user interface, such as server−side programs in Web development, code libraries, and simple applications. The main reason I’m starting you out on the console, though, is that it’s a much easier place to program. Although all those graphic elements make the user’s life easier, they can cause headaches for beginning programmers.

 

The console itself can be thought of as a DOS window. If you’ve been around computing for a while, you probably remember the days when you had to type all your commands into a text−only window. The Console object is the way C# views that window, which is still available in modern computing, and is surprisingly useful. To do anything useful with the console, you need to know how to use the Console class within C#, which ships with documentation describing all the various parts of the language. Looking through this documentation will also give you a sense of how the language is organized.