Tutorial: Create your first .NET Core console application in Visual Studio 2019

This article provides a step-by-step introduction to create and run a Hello World .NET Core console application in Visual Studio 2019. A Hello World application is traditionally used to introduce beginners to a new programming language. This program simply displays the phrase "Hello World!" on the screen.


For more information, see the Install with Visual Studio section on the Install the .NET Core SDK article.

Create the app

The following instructions create a simple Hello World console application:

  1. Open Visual Studio 2019.

  2. Create a new C# .NET Core console app project named "HelloWorld".

    1. On the start window, choose Create a new project.

      Create a new project button selected on the Visual Studio start window

    2. On the Create a new project page, enter console in the search box. Next, choose C# from the Language list, and then choose All platforms from the Platform list. Choose the Console App (.NET Core) template, and then choose Next.

      Create a new project window with filters selected


      If you don't see the .NET Core templates, you're probably missing the required workload installed. Under the Not finding what you're looking for? message, choose the Install more tools and features link. The Visual Studio Installer opens. Make sure you have the .NET Core cross-platform development workload installed.

    3. On the Configure your new project page, enter HelloWorld in the Project name box. Then, choose Create.

      Configure your new project window with Project name, location, and solution name fields

    The C# Console Application template for .NET Core automatically defines a class, Program, with a single method, Main, that takes a String array as an argument. Main is the application entry point, the method that's called automatically by the runtime when it launches the application. Any command-line arguments supplied when the application is launched are available in the args array.

    Visual Studio and the new HelloWorld project

The template creates a simple "Hello World" application. It calls the Console.WriteLine(String) method to display the literal string "Hello World!" in the console window.

Run the app

  1. To run the program, choose HelloWorld on the toolbar, or press F5.

    Visual Studio toolbar with the HelloWorld run button selected

    A console window opens with the text "Hello World!" printed on the screen and some Visual Studio debug information.

    Console window showing Hello World Press any key to continue

  2. Press any key to close the console window.

Enhance the app

Enhance your application to prompt the user for their name and display it along with the date and time. The following instructions modify and run the app again:

  1. Replace the contents of the Main method, which is currently just the line that calls Console.WriteLine, with the following code:

    Console.WriteLine("\nWhat is your name? ");
    var name = Console.ReadLine();
    var date = DateTime.Now;
    Console.WriteLine($"\nHello, {name}, on {date:d} at {date:t}!");
    Console.Write("\nPress any key to exit...");

    This code displays "What is your name?" in the console window and waits until the user enters a string followed by the Enter key. It stores this string into a variable named name. It also retrieves the value of the DateTime.Now property, which contains the current local time, and assigns it to a variable named date. Finally, it uses an interpolated string to display these values in the console window.

  2. Compile the program by choosing Build > Build Solution.

  3. To run the program, choose HelloWorld on the toolbar, or press F5.

  4. Respond to the prompt by entering a name and pressing the Enter key.

    Console window with modified program output

  5. Press any key to close the console window.

Next steps

In this article, you've created and run your first .NET Core application. In the next step, you debug your app.