Back to course

User Input and Output

.NET Zero to Hero: Master C# and Modern App Development

Interacting with the User

To make your programs interactive, you need to read user input.

Reading Input:

Use Console.ReadLine() to get a string from the user.

csharp Console.Write("Enter your name: "); string name = Console.ReadLine(); Console.WriteLine("Hello " + name);

Handling Numbers:

Since ReadLine() returns a string, you must convert it to a number if needed: csharp Console.Write("Enter your age: "); int age = Convert.ToInt32(Console.ReadLine());