internal - Internal types or members are accessible only within files in the same assembly.
protected internal - Access is limited to the current assembly or types derived from the containing class.
So, as you can see “protected internal” can be used in the same assembly or types derived from the containing class in any assembly.
It means that we can access a “protected internal” method by accessing any instance of it’s class in the same assembly, in any class in different assembly which derives from the class, but we won’t be able to access the method by accessing an instance of it’s class in different assembly.
// Assemby : A
namespace AssemblyA
{
public class A
{
protected internal string SomeProtectedInternalMethod() {
return "SomeValue";
}
}
public class A2 : A
{
public string SomeMethod() {
// We can access the method because
// it's protected and inherited by A2
return SomeProtectedInternalMethod();
}
}
class A3 : A
{
public string SomeMethod()
{
A AI = new A();
// We can access the method through an instance
// of the class because it's internal
return AI.SomeProtectedInternalMethod();
}
}
}
// Assemby : B
using AssemblyA;
namespace AssemblyB
{
class B : A
{
public string SomeMethod() {
// We can access the method because
// it's inherited by A2
// despite the different assembly
return SomeProtectedInternalMethod();
}
}
class B2
{
public string SomeMethod()
{
A AI = new A();
// We can't access the method
// through the class instance
// because it's different assembly
return AI.SomeProtectedInternalMethod();
}
}
}