using 指令到底是做什么的?

3

本文介绍了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 指令到底是做什么的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

参数计数与调用不匹配?
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)...
2023-11-11 C#/.NET开发问题
26

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

没有 EndInvoke 的 C# 异步调用?
C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)...
2023-11-11 C#/.NET开发问题
2

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14