123
123

Reputation: 41

what is the access specifier of the top level class in the intermediate language code?

Default access specifier of top level classes in c# is internal but when I observed the IL code it was as follows

.class private auto ansi beforefieldinit n.A
   extends [System.Runtime]System.Object
{
} // end of class n.A

instead of assembly keyword why is the compiler using private keyword in the above IL code?

Upvotes: 1

Views: 616

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1064184

IL defines things differently than C#; in IL there is visibility and accessibility. The details of this are in II.10.1 and table II.10.1.1 of ECMA 335. The only two valid options for top-level types are public and private - everything else relates to nested *, i.e. types within types.

So essentially, it does this because the specification demands it:

A type that is not nested inside another type shall have exactly one visibility (private or public) and shall not have an accessiblity.

There is no such thing as assembly or family for top level types.

Upvotes: 1

Related Questions