.
If you have defined a nested hierarchy of namespaces, code inside that hierarchy might be blocked from accessing the System namespace of the .NET Framework. The following example illustrates a hierarchy in which the SpecialSpace.System namespace blocks access to System.
As a result, the Visual Basic compiler cannot successfully resolve the reference to System.Int32, because SpecialSpace.System does not define Int32. You can use the Global keyword to start the qualification chain at the outermost level of the .NET Framework class library. This allows you to specify the System namespace or any other namespace in the class library. The following example illustrates this.
You can use Global to access other root-level namespaces, such as Microsoft.VisualBasic, and any namespace associated with your project.
You can also use the Global keyword in a Namespace Statement. This lets you define a namespace out of the root namespace of your project.
All namespaces in your project are based on the root namespace for the project. Visual Studio assigns your project name as the default root namespace for all code in your project. For example, if your project is named ConsoleApplication1, its programming elements belong to namespace ConsoleApplication1. If you declare Namespace Magnetosphere, references to Magnetosphere in the project will access ConsoleApplication1.Magnetosphere.
The following examples use the Global keyword to declare a namespace out of the root namespace for the project.
In a namespace declaration, Global cannot be nested in another namespace.
You can use the Application Page, Project Designer (Visual Basic) to view and modify the Root Namespace of the project. For new projects, the Root Namespace defaults to the project name. To cause Global to be the top-level namespace, you can clear the Root Namespace entry so that the box is empty. Clearing Root Namespace removes the need for the Global keyword in namespace declarations.
If a Namespace statement declares a name that is also a namespace in the .NET Framework, the .NET Framework namespace becomes unavailable if the Global keyword is not used in a fully qualified name. To enable access to that .NET Framework namespace without using the Global keyword, you can include the Global keyword in the Namespace statement.
The following example has the Global keyword in the System.Text namespace declaration.
If the Global keyword was not present in the namespace declaration, StringBuilder could not be accessed without specifying Global.System.Text.StringBuilder. For a project named ConsoleApplication1, references to System.Text would access ConsoleApplication1.System.Text if the Global keyword was not used.
Module Module1 Sub Main() Dim encoding As New System.Text.TitanEncoding ' If the namespace defined below is System.Text ' instead of Global.System.Text, then this statement ' causes a compile-time error. Dim sb As New System.Text.StringBuilder End Sub End Module Namespace Global.System.Text Class TitanEncoding End Class End Namespace