Using the Console

Reading from the Console input using ReadLine

Much like writing to the output, the Console API provides various methods for reading input from the user.

using System; public class Program { ...

 

The most common operations are:

  • Read - Reads the next character in the string and returns it as an integer character code.
  • ReadLine - Reads until it finds a new line, carriage return, or the end of your input string, and returns all that it reads as a new string.
  • ReadKey - Reads the next character in the string and returns it as an instance of ConsoleKeyInfo which provides additional information about they key that was pressed, and the state of any modifier keys (like Shift, Alt, etc.)
Page 7 of 12