Compile error when define a class as protected

T

Tony Johansson

Hello!

Can somebody explain why I get this compile error
Elements defined in a namespace cannot be explicitly declared as private,
protected, or protected internal
when compiling this code ?

protected class Test
{
}

//Tony
 
J

Jeff Johnson

Can somebody explain why I get this compile error
Elements defined in a namespace cannot be explicitly declared as private,
protected, or protected internal
when compiling this code ?

protected class Test
{
}

The concept of "protected" is only meaningful when there is a parent--or
perhaps a better term would be "enclosing"--item that can be inherited from.
Types declared directly inside a namespace (as opposed to types declared
inside another type) are a the highest level they can be; there is no parent
or enclosing item. Therefore, protected access has no meaning, and as such
is explicitly disallowed. The same goes with the other access modifiers
mentioned.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top