Name

Imports Statement

Syntax

Imports [aliasname = ] namespace [.element]
aliasname (optional; String literal)

The name by which the namespace will be referenced in the module

namespace (required; String literal)

The name of the namespace being imported

element (optional)

The name of an element in the namespace

Description

Imports namespaces or parts of namespaces, making their members available to the current module

Rules at a Glance

  • A single Imports statement can import one namespace.

  • A module can have have as many Imports statements as needed.

  • Imports statements are used to import names from other projects and assemblies, as well as from namespaces in the current project.

  • Imports statements must be placed in a module before references to any identifiers (e.g., variables, classes, procedures, functions, etc.).

  • namespace must be a fully qualified namespace name, even if you use the /rootnamespace compiler option or supply a value for the “Root namespace” text box in the General tab of a project’s Properties dialog in Visual Studio.

  • If aliasname is absent from an Imports statement, types in that namespace can be referenced without qualification.

  • If aliasname is present in an Imports statement, types in that namespace must be qualified with aliasname in order to be accessible.

  • The name aliasname must not be assigned to any other member within the module.

  • If element is specified, it can be the name of an enumeration, structure, class, or module within the namespace. If specified, this ...

Get VB.NET Language in a Nutshell, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.