C# Hello World

C# is undoubtedly one of the easiest languages to get started in. In this brief tutorial we'll create a "Hello World" console application using Microsoft's free Visual C# express.






Once you've installed Visual C#, go to the File menu and select New Project. Chose Console Application for the project type. Change the name of the application in the text box at the bottom of the dialog to whatever you want, or just leave it at the default. Click OK.

You've now got a program that looks like the following. If you click the green arrow in the toolbar you can run it; nothing will happen except that a console will briefly appear.




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

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




Now let's modify it to make it into a proper "Hello World" app.

In the following code, we've modified the application by adding just two lines.

The first line writes the text "Hello World". The second line waits for you to press a key. The reason the second line is necessary is that otherwise the console is liable to disappear before you can see what's written in it.


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.ReadKey();
        }
    }
}




Hello World




There you have it -- your first C# program. Congratulations old bean.