如果我将一个类声明为内部类,为什么 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/