Organizing Types Within Namespaces

Namespaces are defined within Namespace..End Namespace blocks. Every namespace can expose the following types and members:

• Classes

• Structures

• Enumerations

• Modules

• Interfaces

• Delegates

• Nested namespaces

Listing 9.1 shows an example of a namespaces exposing most of the preceding listed members.

Listing 9.1 Organizing Types Within a Namespace

image

image

As you can see from Listing 9.1, you can organize your custom objects within a namespace. The code implements an abstract class Person, three derived classes (Contact, Employee, and Customer), an interface (which is then implemented by the Contact class), an enumeration (PersonType), a structure (PersonInformation), and a module (GlobalDeclarations). The namespace becomes part of the full name of a type. For example, the full name for the Contact class is People.Contact. Therefore, if you need to access a type defined within a namespace, you need to refer to it writing the full name, as in the following line of code:

Dim firstContact As New People.Contact

Adding Imports

Later in this chapter we discuss the Imports directives that will prevent the need to add the namespace identifier to the full type name every time.

Namespaces can also expose partial classes. This is a common situation within .NET Framework built-in namespaces.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.111.134