Imports Statement


Imports Statement

Syntax

     Imports [aliasName =] namespace[.element] 


aliasName (optional)

The name by which the namespace or element must be referenced within the source-code file that contains the Imports statement


namespace (required)

The name of the namespace being imported


element (optional)

The name of an element in the namespace

Description

The Imports statement makes a namespace or parts of a namespace available to the current module without additional qualification.

Usage at a Glance

  • A single Imports statement can import only one namespace or element.

  • A module can 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 types (classes, structures, etc.).

  • namespace must be a fully qualified namespace name, even if you use the compiler option /rootnamespace or supply a value for the "Root namespace" in the 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 without full qualification. 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.

  • You do not have to 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.

Example

     Imports MVB = Microsoft.VisualBasic 

See Also

Namespace Statement




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

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