Please login to save your progress.

Using the Console

Reading from the Console using Read

We saw previously how to read from the Console using the ReadLine method. Remember how this method reads the an entire line at a time and returns you the input text? Another common operation is the Read method. Unlike ReadLine, the read method returns one character at a time until it reaches the end of the input. This includes, letters, numbers, line breaks, and all other characters.

One of the big differences between Read and ReadLine is that Read doesn't actually return a string, it returns an integer, moreover it returns the ASCII representation of the character you entered. You can find more information about the ASCII character code system in the deep dive section of this tutorial.

To obtain the actual character entered, we need to convert this integer into a character. You can do this a couple of ways, but the simplest, easiest approach is to perform a cast:

 

NOTE: Currently .NET Fiddle does not support the Console.Read operation.

Page 9 of 12