Visual Basic Language Reference  

Namespace Statement

Declares the name of a namespace.

Namespace { name | name.name }
   [ componenttypes ]
End Namespace

Parts

name
Required. A unique name that identifies the namespace.
componenttypes
Optional. Elements that make up the namespace. These include (but are not limited to) enumerations, structures, interfaces, classes, modules, delegates, and other namespaces.
End Namespace
Terminates a Namespace block.

Remarks

Namespaces are used as an organizational system - a way of presenting program components that are exposed to other programs and applications.

Namespaces are always Public; therefore the declaration of a namespace cannot include an access modifiers. However, the components within the namespace may have Public or Friend access. If it is not stated, the default access type is Friend.

Example

The following example declares two namespaces.

Namespace N1   ' Declares a namespace named N1.
   Namespace N2   ' Declares a namespace named N2 within N1.
      Class A   ' Declares a class within N1.N2.
      ' Add class statements here.
      End Class
   End Namespace 
End Namespace

The next example declares multiple nested namespaces on a single line, and is equivalent to the previous example.

Namespace N1.N2 ' Declares two namespaces; N1 and N2.
   Class A   ' Declares a class within N1.N2.
      ' Add class statements here.
   End Class
End Namespace

See Also

Imports Statement | Namespaces