The protected inner class inside the namespace compiles without errors

protected internal class foo
{
    //this compiles without any errors
}

and

internal class bar
{
    public int quix;
    protected internal int zyx;
    //this compiles without any errors
}

Are these compiler errors or misinterpretation of the standard?

Explanation:

  • Classes cannot have a protected internal access modifier, only open or internal according to MSDN (classes and structures declared directly in the namespace (in other words, which are not nested in other classes or structures) can be either public or internal. default value if no access modifier is specified).
  • , (MSDN). . - .

: , Mono, , , , , . , . MSDN, , , .

+5
5

, protected internal protected internal protected internal, :)

/ haacked

:

  • ( ) public internal. HOWEVER, protected internal, private ..

  • , protected internal , , , . ( , Program):

    public class Program
    {
        static void Main(string[] args)
        {
        }
    
        private class Foo
        {
            private int priv { get; set; }
            protected internal int protint { get; set; }
            public int pub { get; set; }
        }
    }
    
+22
+2

MSDN:

, , . , , , .

, , -, .

+2

, , " " - , :

# :

, , ,

!

UPDATE

Mono, //this compiles without any errors, , Mono.

The standard is Microsoft C # compiler behavior. If you ask the question “why is something compiling” and you don’t mention that you are not using the official one , you just make the assumption that the compiler is compiling your code.

Do you want to know which standard? He -again-: Protected classes will always be nested classes!

+2
source

The keyword protectedbelongs to inheritance, and the keyword internalbelongs to scope.

0
source

All Articles