Hello world

The code

using System;
namespace HelloWorld
{
    public class Hello
    {
        public static void Main(String[] args)
        {
	        Console.WriteLine("Hello, World!");
        }
    }
}

Output

Hello, World!

How it works

namespace HelloWorld

{}

public class Hello

public static void Main(String[] args)

What’s special about Main?

Console.WriteLine("Hello, World!");

I don’t understand…

The base for all examples

This hello world program is essentially the base for which all other examples in this tutorial build upon. Whenever you see code examples, you can assume that the code is inside the Main method of the Hello class in the HelloWorld namespace.

using System;
namespace HelloWorld
{
    public class Hello
    {
        public static void Main(String[] args)
        {
            // Any code examples go here unless
            // explicitly stated otherwise.
        }
    }
}

You are welcome to rename the class and namespace to whatever you like, as long as you keep the Main method as it is.

For example, if an example states this code:

int result = 5 + 3;
Console.WriteLine(result);

You can assume that the full code looks like this:

using System;
namespace HelloWorld
{
    public class Hello
    {
        public static void Main(String[] args)
        {
            int result = 5 + 3;
            Console.WriteLine(result);
        }
    }
}