C# User Input

In this lesson, you will learn about the C# User Input, how to use it, along with examples to better understand the topic.


C# User Input Explained

In some circumstances, your program may require user input in order to work properly. For example, a user needs to enter their age to check whether they are eligible to vote. In this case, the Console.ReadLine() function is used, so the user has to enter some value before the program continues to run.

Example


Console.ReadLine() characteristics

In the example above, a user can input their name, which is a string type. The function Console.ReadLine() expects a string from the user input. What if your program requires an integer as a user input? In this case, you have to cast the data type to an integer, as we leavened in the lesson C# Casting – Learnmodo

Example

This concludes the C# User Input lesson. In the next lesson, you will learn about Operators in C#.