Creating First Console Application using Visual Studio

Creating First Console Application using Visual Studio 

In this article, I am going to discuss Creating First Console Application using Visual Studio and C# Programming Language. Please read our previous article where we discussed How to Download and Install Visual Studio on Windows OS.

What is C#?

C# is one of the programming languages provided by Microsoft to work with .Net Framework, as .NET Core Framework and latest .NET. This C# Programming Language provides a Rich Set of Features, which allows us to develop different kinds of applications using the .NET Platform.

C# is an Object-Oriented Programming Language and it contains most of the features of C++ and Java languages as well as some additional features. Now, we will see how to develop our first Console Application using Visual Studio 2022 and using C# Programming Language.

Creating the First Console Application using Visual Studio

A console application is an application that can be run in the command prompt in Windows. For any beginner on .Net, building a console application is ideally the first step to learning the C# Language.

In our example, we are going to use Visual Studio 2022 to create a console-type project. Then we are going to use the console application to display the message “Hello World” on the output screen. We will also see how to build and run the console application. Please follow the below steps to create the console application in visual studio.

Step1

The first step involves the creation of a new project in Visual Studio. For that, open Visual Studio 2022 (the latest version at this point in time) and then click on the Create a New Project option as shown in the below image.

Creating the First Console Application using Visual Studio 2022

Step2

The next step is to choose the project type as a Console application. Type Console in the search bar and you can see different types of console applications using C#, VB, and F# languages using both .NET Framework and Core Framework. Here, I am selecting Console App (.NET Framework) using C# language and then clicking on the Next button as shown in the below image.

Creating First Console Application using Visual Studio and C# Programming Language

Step3

The next step is to configure the new project. Here, you need to provide the project name and solution name. You can also give the same name to both project and solution but it is not mandatory. You need to provide the location where you need to create the project. Here, you also need to provide the .NET Framework version you want to use. The latest version of the .NET Framework is 4.8. So, I am selecting .NET Framework 4.8 and then clicking on the Create button as shown in the below image.

Creating First Console Application using Visual Studio and C# Language

Once you click on the Create button, visual studio will create the Console Application with the following structure.

Console Application Structure

A project called MYFirstProject will be created in Visual Studio. This project will contain all the necessary required files to run the Console application. The Main program called Program.cs is the default code file that is created when a new console application is created in Visual Studio. This Program.cs class will contain the necessary code for our console application. So, if you look at the Program.cs class file, then you will see the following code.

Console Application Program file

Step4

Now let’s write our code which will be used to display the message “Hello World” in the console application. To do so, modify the Main method of the Program class as shown in the below code. In our next article, I will explain the code in detail. For now, simply copy-paste the code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyFirstProject
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Console.ReadKey();
        }
    }
}
Step5

The next step is to run the .Net program. To run any program in Visual Studio, you need to click the Start button as shown in the below image.

Run Application in Visual Studio

Once you click on the Start, you should get the following console window showing the message.

Creating First Console Application

In the next article, I am going to discuss the Basic Structure of the C# Program using a Console Application. Here, in this article, I try to explain Creating First Console Application using Visual Studio and C# Programming Language. and I hope you enjoy this Creating First Console Application using Visual Studio and C# Programming Language article.

Leave a Reply

Your email address will not be published.