When I declare a class as internal, why does the IL show it as private?

前端 未结 3 917
[愿得一人]
[愿得一人] 2021-01-13 10:32

If I declare a class as internal, why does the IL show it as private?

internal class Thing

.class private auto ansi beforefieldinit Thing.Thing
       exten         


        
3条回答
  •  甜味超标
    2021-01-13 10:51

    From IL's point of view, private means private to the assembly, i.e. internal in C#.

    In C#, it is not possible to mark types as private if they are not nested. IL's equivalent accessibility for such types is nested private.

    So we have:

    • C#'s internal -> IL's private (to the assembly)
    • C#'s private -> IL's nested private (to the enclosing type)

提交回复
热议问题