capypad
0 day streak
csharp / beginner
Snippet

Reading User Input

Console.ReadLine is used to pause program execution and wait for the user to type something into the terminal. The input is returned as a string.

snippet.csharp
csharp
1
2
3
Console.Write("Enter your name: ");
string userName = Console.ReadLine();
Console.WriteLine("Hello, " + userName + "!");
Breakdown
1
Console.ReadLine()
Reads a line of characters from the standard input stream.
2
string userName =
Stores the user's typed input into a variable for later use.