Global Keyword


Global Keyword

Syntax

     Global[.namespace...] 


namespace (required)

The name of a top-level namespace, such as System or Microsoft, followed by additional namespace and type qualifiers

Description

New in 2005. The Global keyword provides a way to specify, without ambiguity, a namespace from the topmost level of the namespace hierarchy.

Normally, specifying a full namespace is unambiguous. However, it is possible to create situations where conflicts arise. Consider the following code.

     Imports MyCompany     Namespace MyCompany.System.Configuration        Public Class Configuration           ' ----- Class code here.        End Class     End Namespace     Namespace MyCompany.MyProgram        Public Module GeneralCode           Public Sub SomeRoutine(  )              ' ----- This next line is ambiguous.              Dim whichOne As System.Configuration.Configuration           End Sub        End Module     End Namespace 

The Dim statement in this code is ambiguous because there are now two System.Configuration namespaces: one at the top and one within the MyCompany namespace, both of which contain a Configuration class.

To resolve this conflict, use the Global keyword to specify a full namespace from the very top of the hierarchy. Global appears just before all top-level namespaces. The two classes in this example can each be specified using the Global keyword as follows:

  • Global.System.Configuration.Configuration

  • Global.MyCompany.System.Configuration.Configuration

Version Differences

The Global keyword is new in Visual Basic 2005.

See Also

Continue Statement, On Error 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