This example shows you how to create c# console application in visual studio.

C# Console Application

Console application is a program with no user interface. You can only interact with the application via the command line.

We will create a simple c# console application to print 'Hello World'. This is a simple program to start learning how to create your first program.

In order to create a C# Console Application.

You need to open your visual studio, then select File->New->Project

Next, Select Visual C# Item->Console App (.Net Framework), then enter your project name and click OK button

using System;
using System.Collections.Generic;
using System.Text;

namespace DotNetExample
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, world!");
            Console.ReadLine();
        }
    }
}

To run your project you can press F5.

To prevent a c# console application from closing when it finishes you can call the Console.ReadLine() or Console.ReadKey() method.

You can also pass parameters to the main thread.

static void Main(string[] args)
{
    Console.WriteLine("Number of command line arguments = {0}", args.Length);
    for (int i = 0; i < args.Length; i++)
        Console.WriteLine("Arg[{0}] = [{1}]", i, args[i]);
    Console.ReadLine();
}

For example, we will get the number of command line arguments, then you can print each argument that you entered.