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
Importsstatement can import one namespace.A module can have have as many
Importsstatements as needed.Importsstatements are used to import names from other projects and assemblies, as well as from namespaces in the current project.Importsstatements must be placed in a module before references to any identifiers (e.g., variables, classes, procedures, functions, etc.).If
aliasnameis absent from anImportsstatement, types in that namespace can be referenced without qualification.If
aliasnameis present in anImportsstatement, types in that namespace must be qualified withaliasnamein order to be accessible.The name
aliasnamemust 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
Importsstatement 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.configconfiguration file. For example:<compilation> <namespaces> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access