Ad space (banner)
#๏ธโƒฃC# Lessons
Lesson 58 / 68

Reading from Standard Input

In this lesson you will learn how to read standard input with Console.ReadLine in C#, so your program can respond to what a user types. This is for anyone searching for "C# Console.ReadLine how to use".

Console.ReadLine() reads one line of input from the keyboard or another source. Use it when a command-line tool needs the user to type something.

The sample code prompts with Console.Write("Enter your name: "), reads what was typed into name with Console.ReadLine(), and uses it in a greeting. Notice the difference between Write, which does not add a newline, and WriteLine, which does.

A common stumbling block for beginners is that Console.ReadLine() always returns a string. You have to convert it if you want a number, and forgetting to do so causes errors in your arithmetic.

In real-world development, this is one of the most basic ways for a console application to interact with the user.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run C# directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)