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

前端 未结 3 927
[愿得一人]
[愿得一人] 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 11:06

    On MSDN, it says:

    The C# keywords protected and internal have no meaning in IL and are not used in the reflection APIs. The corresponding terms in IL are Family and Assembly. To identify an internal method using reflection, use the IsAssembly property. To identify a protected internal method, use the IsFamilyOrAssembly.

    So I guess it just makes them private, since they can't be accessed from elsewhere.

    EDIT: I see how my answer might not be completely correct, I just thought it was something worth noting. The MSDN article I linked has some interesting stuff on this "what code we write" - "what it becomes" relationship.

提交回复
热议问题