c# - 当我将一个类声明为内部类时,为什么 IL 将其显示为私有(private)类?

标签 c# .net cil

如果我将一个类声明为内部类,为什么 IL 将其显示为私有(private)?

internal class Thing

.class private auto ansi beforefieldinit Thing.Thing
       extends [mscorlib]System.Object

最佳答案

从 IL 的角度来看,private 意味着程序集私有(private),即 C# 中的internal

在 C# 中,如果类型不是 nested,则无法将类型标记为 private . IL 对此类类型的等效可访问性是 nested private

所以我们有:

  • C# 的internal -> IL 的private(到程序集)
  • C# 的 private -> IL 的 nested private(到封闭类型)

关于c# - 当我将一个类声明为内部类时,为什么 IL 将其显示为私有(private)类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18660300/

相关文章:

c# - 异步任务和锁

.net - "PublicKeyToken <..> is not a valid extension type."错误?

c# - 从 C# 8 中的 System.Reflection.Metadata 获取接口(interface)可为 null 的上下文元数据

c# - 将 IL 包装到 C#/.NET Core 中写在磁盘上的程序集中?

c# - ASP.NET Identity 用户名中的特殊语言字符

c# - ZeroMQ C#HelloWorld示例

c# - Asp.net core默认路由

c# - 使用泛型 T 的 DefineMethod

c# - 从调试版本中的类型获取文件的源代码文件名

.net - 在 .NET 的 RegEx 中,我可以从 Capture 对象获取 Groups 集合吗?