Create First Console App in Visual Studio 2022

This article shows how to create and run a .NET console application in Visual Studio 2022.

First console app in Visual Studio

You may read one of the earlier articles – What’s new in Visual Studio 2022?

Prerequisites

  • Visual Studio 2022
  • The .NET 6 SDK which is automatically installed when you install Visual Studio 2022.

Create First Console App

Once you have installed all the prerequisites then follow the below step to create your first console application in Visual Studio 2022.

  1. Open VS 2022 and click on Create a new project.
Visual Studio Console App

2. Type “console” in the search bar as shown below. Select Console App (C# or VB based on your language expertise)

Create Console App in Visual Studio

3. Give a name to the project and define a folder location as shown in the below screenshot.

4. Select .NET framework and click on Create. I have used .NET 6

You can see 1 line of code in the Program.cs file. Also, you may notice there is no namespace, and no main method. This means there is no extra line of code.

Console.WriteLine("Hello, World!");

Press F5 to run the application and you will see the output.

Now, let’s enhance this project and add a new class.

I have added a class called Book which has only one method GetBookName()

namespace ConsoleApp2
{
    public class Book
    {
        public string GetBookName()
        {
            return "Dot Net Core E-Book";
        }
    }
}

In the Program.cs file, add using statement and create the object of class Book to call the method. (The similar way which we have been doing in C# coding.)

using ConsoleApp2;

Console.WriteLine("Hello, World!");
Book book = new Book();
Console.WriteLine(book.GetBookName());

So, in this way, we have created a very basic Console Application using Visual Studio 2022 and .NET 6.

Hope you like this article.

Leave a Comment

RSS
YouTube
YouTube
Instagram