2.16. Read User Input from the Console


You want to read user input from the Windows console, either a line or character at a time.


Use the Read or ReadLine method of the System.Console class to read input when the user presses Enter. To read input without requiring the user to press Enter, use the Console.ReadKey method.

How It Works

The simplest way to read input from the console is to use the Shared Read or ReadLine methods of the Console class. These methods will cause your application to block, waiting for the user to enter input and press Enter. In both instances, the user will see the input characters in the console. Once the user presses Enter, the Read method will return an Integer value representing the next character ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with O’Reilly online learning.

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