C# can read keyboard input from the console. In this section you will learn how to do that..
To get keyboard input, first open a console to run your program in. Then it will ask for keyboard input and display whatever you’ve typed.
The C# program below gets keyboard input and saves it into a string variable. The string variable is then shown to the screen.
string city = null;
The data that we read from the console (keyboard), is stored in a variable and printed to the screen.
Sample output of program.
Enter city name: Sydney
You live in Sydney
city = Console.ReadLine();
- Make a program that lets the user input a name
- Get a number from the console and check if it’s between 1 and 10.