protected internal class foo
{
//this compiles without any errors
}
also
internal class bar
{
public int quix;
protected internal int zyx;
//this compiles without any errors
}
Are these compiler bugs or my misinterpretation of the standard?
Explanation:
- Classes can’t have protected internal access modifier, only public or internal according to MSDN (Classes and structs that are declared directly within a namespace (in other words, that are not nested within other classes or structs) can be either public or internal. Internal is the default if no access modifier is specified).
- Not all access modifiers can be used by all types or members in all contexts, and in some cases the accessibility of a type member is constrained by the accessibility of its containing type (MSDN). Public should fail. Protected internal is ambiguous for me – internal modifier is not necessary.
Edit: The fact that I’m using Mono is unnecessary cause the question was about what standard says and not what MONO does or does not. Maybe I’m coding my own compiler. That’s why I quoted MSDN to be precise what is allowed and what is not.
As mentioned in my comment above,
protected internalmeansprotectedorinternalNOTprotectedandinternal. No bug here 🙂Further information/explanation is on haacked
In response to your questions:
A class within a namespace (and not within another class) can only be declared as
publicorinternal. HOWEVER, a class within another class can be declared asprotected internal,private, etc.Yes,
protected internalcan be used inside a class whose access modifier is more strict than it’s members, see example of a perfectly valid usage below (note that the class is inside theProgramclass):