Quickstart: Use Visual Studio to create your first C# console app

In this 5-10 minute introduction to the Visual Studio integrated development environment (IDE), you'll create a simple C# app that runs on the console.

If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.

If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.

Create a project

First, you'll create a C# application project. The project type comes with all the template files you'll need, before you've even added anything!

  1. Open Visual Studio 2017.

  2. From the top menu bar, choose File > New > Project.

  3. In the New Project dialog box in the left pane, expand C#, and then choose .NET Core. In the middle pane, choose Console App (.NET Core). Then name the project HelloWorld.

    Console App (.NET Core) project template in the New Project dialog box in the Visual Studio IDE

    If you don't see the Console App (.NET Core) project template, choose the Open Visual Studio Installer link in the left pane of the New Project dialog box.

    Choose the Open Visual Studio Installer link from the New Project dialog box

    The Visual Studio Installer launches. Choose the .NET Core cross-platform development workload, and then choose Modify.

    .NET Core cross-platform development workload in the Visual Studio Installer

  1. Open Visual Studio 2019.

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

    'Create a new project' window

  3. On the Create a new project window, enter or type console in the search box. Next, choose C# from the Language list, and then choose Windows from the Platform list.

    After you apply the language and platform filters, choose the Console App (.NET Core) template, and then choose Next.

    Choose the C# template for the Console App (.NET Framework)

    Note

    If you do not see the Console App (.NET Core) template, you can install it from the Create a new project window. In the Not finding what you're looking for? message, choose the Install more tools and features link.

    The 'Install more tools and features' link from the 'Not finding what you're looking for' message in the 'Create new project' window

    Then, in the Visual Studio Installer, choose the .NET Core cross-platform development workload.

    .NET Core cross-platform development workload in the Visual Studio Installer

    After that, choose the Modify button in the Visual Studio Installer. You might be prompted to save your work; if so, do so. Next, choose Continue to install the workload. Then, return to step 2 in this "Create a project" procedure.

  4. In the Configure your new project window, type or enter HelloWorld in the Project name box. Then, choose Create.

    in the 'Configure your new project' window, name your project 'HelloWorld'

    Visual Studio opens your new project.

Create the application

After you select your C# project template and name your project, Visual Studio creates a simple "Hello World" application for you.

Visual Studio includes default "Hello World" code in your project.

(To do so, it calls the WriteLine method to display the literal string "Hello World!" in the console window.)

View the default Hello World code from the template

If you press F5, you can run the program in Debug mode. However, the console window is visible only for a moment before it closes.

(This behavior happens because the Main method terminates after its single statement executes, and so the application ends.)

Add some code

Let's add some code to pause the application so that the console window doesn't close until you press ENTER.

  1. Add the following code immediately after the call to the WriteLine method:

    Console.ReadLine();
    
  2. Verify that it looks like this in the code editor:

    Add code to pause the Hello World app

Run the application

  1. Choose the HelloWorld button on the toolbar to run the application in Debug mode. (Or, you can press F5.)

    Choose the Hello World button to run the app from the toolbar

  2. View your app in the console window.

    Console window showing Hello World!

Close the application

  1. Press ENTER to close the console window.

  2. Close the Output pane in Visual Studio.

    Close the Output pane in Visual Studio

  3. Close Visual Studio.

Next steps

Congratulations on completing this Quickstart! We hope you learned a little bit about C# and the Visual Studio IDE. To learn more, continue with the following tutorials.