C#程序集,程序集中的内容是什么? [英] C# assemblies, whats in an assembly?

查看:349
本文介绍了C#程序集,程序集中的内容是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解C#中的内部访问修饰符.我似乎无法理解确切的程序集是什么,以及程序的哪一部分保留在该程序集中.我试图这样做,以便变量只能由以下命名空间中的对象访问:

I'm trying to understand the internal access modifier in C#. I can't seem to understand what an assembly is exactly, and what part of my program is held inside that assembly. I was trying to make it so that a variable is accessibly only by objects within the following namespace:

namespace Engine.Entity

有问题的变量是在该名称空间内的类中定义的,因此我假设如果将其设置为内部,则只有该名称空间内的对象才能访问它.我将程序集和名称空间视为一个,但我认为这是不对的.

The variable in question is defined in a class inside of that namespace, so I assumed if I made it internal, only objects inside of that namespace have access to it. I am seeing assemblies and namespaces as one, and I don't think that's right.

推荐答案

命名空间仅影响名称解析.命名空间并不意味着任何形式的存储,命名空间也不能确定哪些DLL包含您的代码.使用命名空间,即使它们可能物理上驻留在不同的DLL中,您也可以将它们以逻辑名称分组在一起.

Namespaces affect name resolution only. Namespaces do not imply any sort of storage, nor do namespaces determine which DLLs contain your code. Namespaces allow you to group related things together under a logical name even though they may physically reside in different DLLs.

程序集基本上只是一个DLL或EXE文件.它包含IL代码和描述该DLL或EXE中的代码的类型信息.它也可以包含很多其他内容,但是对于初学者来说,只需将其视为DLL即可.

An assembly is basically just a DLL or EXE file. It contains IL code and type information that describes the code in that DLL or EXE. It can contain a lot of other stuff too, but for starters just think of it as a DLL.

通过将代码编译到产生DLL或EXE的项目(csproj)中,将代码放入特定的程序集中.

You put your code into a particular assembly by compiling your code into a project (csproj) that produces the DLL or EXE.

名称空间可以跨越多个程序集.也就是说,属于该逻辑名称空间的成员的类可以驻留在多个DLL中.仅当您的项目引用包含该类的正确程序集(DLL)时,才能访问源代码中的特定类.

A namespace can span multiple assemblies. That is, classes that are members of that logical namespace may reside in multiple DLLs. You can access a particular class in your source code only if your project references the correct assembly (DLL) that contains that class.

内部修饰符表示只能从同一程序集中访问该符号.只有编译为与您的代码相同的DLL的代码才能访问标记为internal的属性或方法.

The Internal modifier means that the symbol can only be accessed from within the same assembly. Only code that is compiled into the same DLL as your code can access your properties or methods that are tagged with internal.

这篇关于C#程序集,程序集中的内容是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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