Home:ALL Converter>Defined Elements cannot be explicitly declared as private or protected

Defined Elements cannot be explicitly declared as private or protected

Ask Time:2014-04-03T21:04:47         Author:Thomas

Json Formatter

According to object oriented principles, we can define any class in any namespace as private or protected but when I create a class as private or protected I get the following compilation error:

Elements defined in a namespace cannot be explicitly declared as private, protected, or protected internal

namespace test
{
    public class A
    {
        public A()
        {
        }
    }

    protected  class B //throwing error
    {
    }
}

I searched for a solution and I found the following on Stack Overflow:

Anything that is not a member of an enclosing type (class) doesn't make sense at all to be protected.

Why can't I declare B as protected?

I guess I don't understand what protected means. What does it mean?

Author:Thomas,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/22838668/defined-elements-cannot-be-explicitly-declared-as-private-or-protected
Sam Leach :

Only nested classes can be marked as protected.\n\nnamespace test\n{\n public class A\n {\n public A() { }\n\n protected class B\n {\n public B() { }\n }\n } \n}\n",
2014-04-03T13:10:37
Murdock :

Protected says that the class can only be used inside the class it is specified in or inherited from. Therefore it does not make sense to declare a protected class in a namespace. What would this mean? Protected can only be applied to nested classes therefore.",
2014-04-03T13:11:22
yy