Welcome to C# Console Examples Series 1. In this post, we show how to read a name from the user in a console application and print it back.
You can use Console.ReadLine() to get input from the user. The example below asks for your name and then prints the entered name to the screen.
using System;
class Program
{
static void Main()
{
Console.Write("Enter your name: " );
string name = Console.ReadLine();
Console.WriteLine("Hello " + name);
}
}
For example, if the user enters `John Smith`, the output will be:
Hello John Smith
Copy this code into Program.cs in a new C# Console project and run it to try it yourself.