Skip to content

USING(命名空间)


将命名空间中的符号引入当前作用域

语法

Using identifier [, identifier [, ...] ]

参数

identifier: 要使用的 Namespace 名称。

说明

Using 命令允许不带命名空间名称前缀就能访问给定命名空间中的所有符号。与 C++ 不同,但与 C# 类似,Using 后不需要 Namespace 关键字,因为不能从命名空间继承单个符号。

Using 只允许在命名空间和过程中使用(不能在类型、联合或枚举声明中使用)。

继承整个命名空间可以减少打字量,但有时可能会失去代码的某些含义,并可能与其他符号产生冲突。

示例

start GeSHi

vb
Namespace Sample
    Type T
        x As Integer
    End Type
End Namespace

'' Just using the name T would not find the symbol,
'' because it is inside a namespace.
Dim SomeVariable As Sample.T

'' Now the whole namespace has been inherited into
'' the global namespace.
Using Sample

'' This statement is valid now, since T exists
'' without the "Sample." prefix.
Dim OtherVariable As T

end GeSHi

版本

  • 在 fbc 1.09.0 之前,如果全局命名空间(未命名命名空间)中有重复符号,对局部符号的访问会被重复的全局符号捕获(在这种情况下,需要完整前缀才能访问局部符号)。

与 QB 的区别

  • QB 有 Using 关键字,但用于其他目的。QB 中不存在命名空间。

另请参阅

  • Print Using
  • ? Using
  • Palette Using
  • Namespace

返回 目录

基于 FreeBASIC 官方文档翻译 如有侵权请联系我们删除
FreeBASIC 是开源项目,与微软公司无隶属关系