The first Application

Namespaces

Mono ships with more than 3000 classes. Additionally there are libraries like Gtk# (650 classes), that make this number even bigger.Most likely, There are some two classes in Mono, that have the same name, or you want to create a new class, that has a name already used. That's why the concept of namespaces exists. Each class in the Mono Class library is put in a namespace.

For example the Console class we use is in the System namespace. The Window class is in the Gtk namespace. Classes in namespaces must be accesed by putting the namespace in front of the class name.

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

// instead of Console.WriteLine("Hello, World!");
This can result in pretty much typing work, so you can use such namespaces. This will, that the compiler will look in all used namespaces for the class. If it is found twice it will give an error. So instead of writing System.Console... we can write:
using System;

...

Console.WriteLine("Hello, World!");
It is common to use at least System. Nobody would write System.Console.WriteLine().

You can also put your own code in namespaces. All you have to do is:

namespace mynamespace {

// ...

}
You can also put a namespace inside another namespace:
namespace HigherNamspace {

namespace mynamespace {

// ...

}

}
This is equal to:
namespace HigherNamspace.mynamespace {

// ...

}