Creating Namespaces

The last OOP topic we'll look at in this chapter is how to create your own namespaces. As you know, namespaces let you divide programs up to avoid clashes between identifiers (even if you don't declare your own namespace, your code is given its own default namespace, the global namespace). To create your own namespace, you use the namespace keyword:

namespace name[.name1] ...] {
  type-declarations
}

Here are the parts of this statement:

  • name, name1 A namespace name can be any legal identifier, and it can include periods.

  • type-declarations Within a namespace, you can declare one or more of the following types: another namespace, a class, interface, struct, enum, or delegate.

You can create as many namespaces in a file as ...

Get Microsoft® Visual C#® .NET 2003 Kick Start now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.