Global
更新:2007 年 11 月
使您可以在已使用命名空间结构阻塞 .NET Framework 编程元素时对其进行访问。
备注
如果已定义命名空间的嵌套层次结构,该层次结构中的代码将被阻塞而无法访问 .NET Framework 的 System 命名空间。下面的示例演示了 SpecialSpace.System 命名空间阻塞对 System 的访问的层次结构。
Namespace SpecialSpace
Namespace System
Class abc
Function getValue() As System.Int32
Dim n As System.Int32
Return n
End Function
End Class
End Namespace
End Namespace
因此,Visual Basic 编译器不能成功解析对 System.Int32 的引用,因为 SpecialSpace.System 没有定义 Int32。可以使用 Global 关键字启动 .NET Framework 类库最外层的限定链。这使您可以指定此类库中的 System 命名空间或任何其他命名空间。下面的示例演示这一点。
Namespace SpecialSpace
Namespace System
Class abc
Function getValue() As Global.System.Int32
Dim n As Global.System.Int32
Return n
End Function
End Class
End Namespace
End Namespace
可以使用 Global 访问其他根级别的命名空间(如 Microsoft.VisualBasic)以及与您的项目关联的任何命名空间。
Global 关键字可用于下面的上下文中:
For Each...Next 语句 (Visual Basic)
Try...Catch...Finally 语句 (Visual Basic)