Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protected Internal method not allowing Internal Class as parameter

Tags:

c#

This code does not compile:

internal class Foo {}

public abstract class SomeBaseClass
{
    protected internal void ProcessFoo(Foo value)
    {
        // doing something...
    }
}

The compile fails stating:

Inconsistent accessibility: parameter type Foo is less accessible than method SomeBaseClass.ProcessFoo

like image 390
Sellorio Avatar asked May 25 '16 02:05

Sellorio


People also ask

What's the difference between protected and internal What about protected internal?

protected: The type or member can be accessed only by code in the same class , or in a class that is derived from that class . internal: The type or member can be accessed by any code in the same assembly, but not from another assembly.

What is the correct definition of protected internal?

A protected internal member of a base class is accessible from any type within its containing assembly. It is also accessible in a derived class located in another assembly only if the access occurs through a variable of the derived class type.

What is protected internal access modifier?

Protected Internal access modifier is combination Protected or Internal. Protected Internal Member can be available within the entire assembly in which it declared either creating object or by inherited that class. And can be accessible outside the assembly in a derived class only.

Can internal class have public methods?

The short answer is that it doesn't matter. Public methods of an internal class are internal. To the compiler, the internal/public method distinction only matters for public classes.


1 Answers

Apparently, protected internal means protected or internal and not protected and internal as I had believed.

Credit to Michael Liu

like image 172
Sellorio Avatar answered Nov 11 '22 14:11

Sellorio