Compile error when define a class as protected

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
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
 
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.
 
Back
Top