Name
Imports Statement
Syntax
Imports[aliasname = ] namespace
-
aliasname
Use: Optional
Type: String literal
The name by which the namespace will be referenced in the module
-
namespace
Use: Required
Type:
The name of the namespace being imported
Description
Imports namespaces and assemblies, making their classes and class 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.).If
aliasname
is absent from anImports
statement, types in that namespace can be referenced without qualification.If
aliasname
is present in anImports
statement, types in that namespace must be qualified withaliasname
in order to be accessible.The name
aliasname
must not be assigned to any other member within the module.
Programming Tips and Gotchas
In ASP.NET, a number of namespaces are imported automatically. These include System.Web and its child namespaces.
You do not use the
Imports
statement to import namespaces into an ASP.NET application. Instead, you can import a namespace into an ASP.NET application in a number of ways:By creating an
<add namespace>
directive in aweb.config
configuration file. For example:<compilation> <namespaces> ...
Get VB .NET Language in a Nutshell 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.