Imports Statement

   
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 restricts importation to members of that element only.

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 a web.config configuration file. For example:

       <compilation>     <namespaces>       <add namespace   ="   System.IO   "   />       ...    </namespaces> 

      imports the System.IO namespace within the scope defined in the web. config file.

    • By adding an @ Import directive to global.asax . For example:

       <%@ Import namespace="System.IO" %> 

      imports the System.IO namespace for the ASP.NET application.

    • By adding an @ Import page directive. This has the same form as the global.asax directive, and must appear at the beginning of the page.

See Also

Namespace Statement

   


VB.Net Language in a Nutshell
VB.NET Language in a Nutshell
ISBN: B00006L54Q
EAN: N/A
Year: 2002
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net