Reading from the Console
In the previous step, we printed the game board to the console. In this one, we will implement a player's move.
Console.ReadLine
In C#, reading data from the console is done using the
Console.ReadLine() method. This method reads a line of text entered by the user and returns it as a string. Line 1, Char 1
Converting from string to number
If you need to read a number, the string can be converted to the required numeric type using the
int.Parse() method. Line 1, Char 1
Exercises
- Read your last name and first name, and print them on one line using interpolation.
Line 1, Char 1
- What year were you born? Read the year, calculate your age (current year - entered year), and print it.
Line 1, Char 1