What does the using directive do, exactly?(using 指令到底是做什么的?)
问题描述
在 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 指令到底是做什么的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:using 指令到底是做什么的?


基础教程推荐
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01