console readline in csharp

To read input from the console window in C#, we can make use of the Console.ReadLine() method. Here is an example usage:

main.cs
// Prompt user for input
Console.Write("Enter your name: ");

// Read input from the console window
string name = Console.ReadLine();

// Print the input to the console window
Console.WriteLine($"Hello, {name}!");
214 chars
9 lines

In the above example, we first prompt the user for input by using Console.Write() to display the string "Enter your name: " on the screen. We then use Console.ReadLine() to wait for user input, and store the input in the name variable. Finally, we print a message to the console window using Console.WriteLine(), which includes the user's input.

gistlibby LogSnag