问题描述
在 MSDN 上我可以阅读它的作用,但我想知道它在技术上做了什么(告诉编译器在哪里寻找类型..)?我的意思是作为指令使用.
On MSDN I can read what it does, but I would like to know what it does technically (tells compiler where to look for types..)? I mean using as a directive.
推荐答案
using
指令的主要功能是使命名空间中的类型无需对用户代码进行限定即可使用.它考虑了在引用的程序集中定义的一组命名空间和类型以及正在编译的项目.
The primary function of the using
directive is to make types within a namespace available without qualification to the user code. It considers the set of namespaces and types which are defined in referenced assemblies and the project being compiled.
以MyTypes.Dll中的如下定义为例
Take for example the following definition in MyTypes.Dll
namespace MyTypes {
class Class1 {}
}
现在考虑从另一个具有不同命名空间的项目中引用 MyTypes.dll
.如果没有使用指令来创建 Class1
我需要限定名称
Now consider referencing MyTypes.dll
from another project with a different namespace. Without a using directive to create Class1
i need to qualify the name
MyTypes.Class1 local1 = new MyTypes.Class1();
using
指令让我可以删除这个限定符
The using
directive lets me remove this qualification
using MyTypes;
...
Class1 local1 = new Class1();
这篇关于using 指令到底是做什么的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!