DLL和命名空间在C#中的关系 [英] Relation between DLLs and Namespaces in C#

查看:141
本文介绍了DLL和命名空间在C#中的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里高级别问题:

我花了很多时间当今教育自己基本的高层次的概念,如原料药,静态和动态库文件,DLL和编组在C#。获得所有这些知识使我对什么似乎像pretty的基本问题,而且很可能表明一个洞,我对这些概念的理解:

I have spent a lot of time today educating myself on basic high-level concepts such as APIs, static and dynamic libraries, DLLs and marshaling in C#. Gaining all of this knowledge led me to what seems like a pretty basic question, and probably demonstrates a hole in my understanding of these concepts:

我所知道的:

  • 在DLL文件可能包含这几个我想要用我的程序,利用类又包含不同的阶级成员,如方法和字段,
  • 在我们使用使用的的code顶部的关键字C#,定义一个命名空间,我们 希望在我们的计划,包括
  • DLLs may contain classes which in turn contains various class-members such as methods and fields, several of which I might want to utilize in my program
  • In C# we use the keyword "using" at the top of the code, to define a namespace we want to include in our program

我不明白是什么:

我是根据实际方法的DLL文件中定义的IM pression。怎么我的程序查找在DLL中定义的实际功能,当所有我给他们的是一个命名空间?这似乎更直观的我用XYZ.dll在顶部,有而不是用XYZ_namespace。

I was under the impression that the actual methods were defined in the DLLs. How does my program find the actual functions that are defined in the DLLs, when all i give them is a namespace? It seems more intuitive to me to have "using XYZ.dll" at top, rather than "using XYZ_namespace".

非常感谢帮助我在这里填写的空白。

Thanks a lot for helping me fill in the gaps here.

编辑:修改后要具体到C#

编辑2:对于其他人是不知道自己的C#应用​​程序实际上得到了保持所提供的类型,通过使用namespaceX,这是一个很好的资源(除了下面有帮助的帖子):<一HREF =htt​​p://broadcast.oreilly.com/2010/07/understanding-c-namespaces-and.html rel="nofollow">http://broadcast.oreilly.com/2010/07/understanding-c-namespaces-and.html.

EDIT 2: For other people that wonder how their C# application actually gets a hold of the types made available through "using namespaceX", this is a good resource (in addition to the helpful posts below): http://broadcast.oreilly.com/2010/07/understanding-c-namespaces-and.html.

基本类型,你想用驻留在库中,你必须设置Visual Studio中,以使人们有可能利用它的命名空间中的code参考这些库。

推荐答案

在C#中,DLL文件(即组件)包含 ES(和其他类型)。这些类型通常有很长的全名,如 System.Collections.Generic.List&LT; T&GT; 。这些类型可以包含方法。

In C#, DLLs (aka assemblies) contain classes (and other types). These types typically have long full names, like System.Collections.Generic.List<T>. These types can contain methods.

在你的引用区域,您必须引用程序集(这是你的.csproj文件的一部分)。在cs文件,你并不需要包含任何使用来引用这个DLL,因为它已经在你的.csproj的文件中引用。

In your References area, you have references to assemblies (this is part of your .csproj file). In a .cs file, you don't need to include any using to reference this DLL, because it's already referenced in your .csproj file.

如果您有这样一行使用System.Collections.Generic; ,它告诉C#编译器来查找 System.Collections.Generic。名单&LT; T&GT; 当你键入名单,其中,T&GT; 。你不需要做这样的说法,但是:你可以简单地键入 System.Collections.Generic.List&LT; T&GT;

If you include a line like using System.Collections.Generic;, that tells the C# compiler to look for System.Collections.Generic.List<T> when you type List<T>. You don't need to do it that way, however: you can simply type System.Collections.Generic.List<T>.

这篇关于DLL和命名空间在C#中的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆