CS First Console Application

C # is one of Microsoft's languages for working with. Net. This language includes a wide range of features, which allow different applications to be developed.

C # is a programming language orientated towards the object and resembles several C++ language aspects. In this tutorial, our first application can be developed.

We will then explore various data types in the C # language as well as control flow statements. This is a basic console application.

An application for a console is an application that can be launched in the Windows prompt. For any beginner on .Net, the first step is ideally to build a console application.

  • We will use Visual Studio in our example to create a project type console.
  • Then we'll show the "Hello World" message with the console application.
  • We will then see how the console application is built and run.

 

 

Step 1. The first step is to create a new Visual Studio project. We must therefore choose the New->Project menu option when the Visual Studio is launched.

C# Create First Application

Step 2. The next step is to use a console application for the project type. The name and location of our project must also be mentioned here.

C# Create First Application Hello World

  1. We can see different options in the project dialog box for creating different types of Visual Studio projects. On the left - hand side click the Windows option.
  2. By clicking on the options for Windows in the previous step, the Console Application option can be viewed. Click this option.
  3. We give the application a name that is DemoApplication in our case. We must also provide our application with a place to store.
  4. Finally, let Visual Studio create our project by clicking on the ' OK ' button.

We get the output below in Visual Studio if we follow the steps above.

Output

C# Solution Explorer Window

  1. Visual Studio will create a project called "DemoApplication". This project contains all the artifacts necessary for running Console.
  2. Programm.cs is the default code file that is created in Visual Studio when a new application is created. The code for our console application contains the code needed.

 

Step 3. Let us now write down our code which can be used in the console application to view the "Hello World" string.

C# Explanation of Code

Note: Every code in the program.cs file must be entered below. When the console application is running the code will be used to write "Hello World".

C# Hello World Program


using System;

namespace DemoApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Hello Word!");
            Console.ReadKey();
        }
    }
}

 

  1. Default lines entered by Visual Studio are the first lines of code. The statement "using" is used in our console application for the import of existing .net modules. For any. Net application, these modules are necessary to work correctly. The bare minimum code to work with a Windows machine is included.
  2. Each application belongs to a class. C# is an object - oriented language, and therefore all code needs to be defined in a self - supporting module known as a "Class" each class belongs to a namespace.
  3. The primary function is an automatically called function when a console application is running. We must here ensure that we enter the necessary code in the console application to display the necessary string.
  4. The console class in .Net is available for console applications. Here we are writing the string "Hello World" on the console by using an built - in method called "Write".
  5. Then we use Console ReadKey() to read the console key. The program will wait and not leave immediately when entering this code line. The program will wait before the user finally leaves any key. If this statement is not included in the code, the program will be released as soon as it is executed.

 

 

Setp 4. Run the program with .Net. We need to click Visual Studio to run any program.

Run C# Application

Output:

The following output will be displayed when the above code has correctly been entered and the program executed successfully. We can see clearly from the output that the "Hello World" string is shown correctly. The Console .Write declaration causes the string to be sent to the console.

C# Console output

 

  • A console application can be executed on a windows machine at the command prompt.
  • We can use the Console .Write method to write console content.
  • C# is available in integer, double, boolean, and string basic data types.
  • Constant values are declared using enumerations. In the C # listing, the enum keyword is declared.
  • Different C# operators are largely classified in the arithmetic, relation and logical categories.
  • Variables are used to indicate memory locations containing data type values.
  • Array elements of the same type are stored with arrays. Values may be assigned to individual array elements.

 

C# Hellow World Console Appliction