C# TUTORIAL

Your First Hello World Program



Start Visual C# Express. If you run the C# for the first time it will take slightly more time as it configures the environment for the first time. Once C# is running select File -> New project. From the project dialog, select the Console application. This is the most basic application type on a Windows system,. Once you click Ok, Visual C# Express creates a new project for you, including a file called Program.cs. It should look something like this:


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
        }
    }
}





Now write the following two line within the inner two braces

Console.WriteLine("Hello, world!");
Console.ReadLine();

The whole thing now should look as follows

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

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


Hit F5 to run the above code. If you have not make any typographical mistake the program will actually run and display a black window displaying Hello World.

In the two lines that we wrote the first lin Writes a line in the console window. The second line reads a line in the window.

The second line is required because, without it the program will run and come out of it. So before you could observe the output on the console window, the program finishes the task and the console window is closed. Try running the code with only the first line and see what happens.

You have completed the installation of your first c# program. In the next chapter we will develop detailed C# concepts.