Can a class be protected in.NET?
Why is / isn’t this possible?
Can a class be protected in.NET? Why is / isn’t this possible?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, you just cannot make them top level classes, they must be inner classes
This is fine, it means that the only classes allowed to see Foo are sub classes of Outer
Note that you cannot declare any outer class as private, protected (or protected internal) in c# since the access modifier for outer level classes defines their visibility in relation to other assemblies. Specifically visible within the assembly only (or to friends via InternalsVisibleTo) or outside the assembly.
Thus whilst the public/internal identifiers are used here for consistency really the state in IL is simply ‘Public’ or ‘NonPublic’ (as the Reflection.Emit flags show)