Export (0) Print
Expand All

6.4 Namespaces

Visual Studio .NET 2003

Visual Basic .NET programs are organized using namespaces. Namespaces both internally organize a program as well as organize the way program elements are exposed to other programs.

Unlike other entities, namespaces are open-ended, and may be declared multiple times within the same program and across many programs, with each declaration contributing members to the same namespace. In the following example, the two namespace declarations contribute to the same declaration space, declaring two classes with the fully qualified names N1.N2.A and N1.N2.B.

Namespace N1.N2
    Class A
    End Class
End Namespace

Namespace N1.N2
    Class B
    End Class
End Namespace

Because the two declarations contribute to the same declaration space, it would be an error if each contained a declaration of a member with the same name.

There is a global namespace that has no name and whose nested namespaces and types can always be accessed without qualification. The scope of a namespace member declared in the global namespace is the entire program text. Otherwise, the scope of a type or namespace declared in a namespace whose fully qualified name is N is the program text of each namespace whose corresponding namespace's fully qualified name begins with N or is N itself.

In this example, the class B can see the class A because B's namespace N1.N2.N3 is conceptually nested within the namespace N1.N2.

Namespace N1.N2
    Class A
    End Class
End Namespace

Namespace N1.N2.N3
    Class B
        Inherits A
    End Class
End Namespace

See Also

6.4.1 Namespace Declarations | 6.4.2 Namespace Members | 6.2 Compilation Options | 6.3 Imports Statement | Namespace Statement (Visual Basic Language Reference) | Namespaces (Visual Basic Language Concepts)

Show:
© 2014 Microsoft