This documentation is archived and is not being maintained.

4.1 Declarations

Visual Studio .NET 2003

A Visual Basic .NET program is made up of named entities. These entities are introduced through declarations and represent the "meaning" of the program.

At a top level, namespaces are entities that organize other entities, such as nested namespaces and types. Types are entities that describe values and define executable code. Types may contain nested types and type members. Type members are constants, variables, methods, properties, events, enumeration values, and constructors.

An entity that can contain other entities defines a declaration space. Entities are introduced into a declaration space either through declarations or inheritance; the containing declaration space is called the entities' declaration context. Declaring an entity in a declaration space in turn defines a new declaration space that can contain further nested entity declarations; thus, the declarations in a program form a hierarchy of declaration spaces.

Except in the case of overloaded type members, it is invalid for declarations to introduce identically named entities of the same kind into the same declaration context. Additionally, a declaration space may never contain different kinds of entities with the same name; for example, a declaration space may never contain a variable and a method by the same name.

The declaration space of a namespace is "open ended," so two namespace declarations with the same fully qualified name contribute to the same declaration space. In the example below, the two namespace declarations contribute to the same declaration space, in this case declaring two classes with the fully qualified names Data.Customer and Data.Order:

Namespace Data
    Class Customer
    End Class
End Namespace

Namespace Data
    Class Order
    End Class
End Namespace

Because the two declarations contribute to the same declaration space, a compile-time error would occur if each contained a declaration of a class with the same name.

See Also

4.1.1 Overloading and Signatures | 4.3 Inheritance | 4.4 Implementation | 4.5 Polymorphism | 4.6 Accessibility | 4.2 Scope | 4.7 Type and Namespace Names | 4.7.1 Qualified Name Resolution | 5. Attributes