Back to Blog
Author: Published 40 views
C# Console Examples Series 1

C# Console Examples Series 1

A beginner-friendly C# Console example that reads a name from the user and prints it back.

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.

CSHARP
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:

Code
Hello John Smith

Copy this code into Program.cs in a new C# Console project and run it to try it yourself.