Part 12 - Namespaces
A name that uniquely identifies a set of objects so there is no ambiguity when objects from different sources are used together.
Namespaces are useful because if you have, for example, a
namespace and a
namespace, and they both have a
class, you can refer to
Furniture.Leg and be clear about which
class you are mentioning.
Declaring a Namespace
To declare a
namespace, all that is required is that you put
namespace followed by a name at the top of your file.
This creates your
Tutorial.Thing. While coding inside your
namespace, it will be transparently
To declare a
namespace within a
namespace, just place a dot . inbetween each other.
Importing Another Namespace
classes from another
namespace, you would use the
The most common
namespace you will import is
Both produce the exact same code, it's just easier and clearer with the
Don't be afraid to
If you are importing from another assembly, you would use the phrase
import <target> from <assembly>, for example
System.Data is part of an external library which can be added, System.Data.dll. Gtk is part of the Gtk# library, which, since it has a special name (with a dash in it), it must be quoted.
Only use the
- Figure out a good exercise for this section.
Go on to Part 13 - Enumerations