C# Protected Internal
I’ve noticed that most of the c# developers i’am talking to, know exactly what “public”, “private”, “protected” and “internal” access modifiers mean and how to use them, but when it comes to “protected internal” they start guessing the answer and it’s never the right one.
Well, let’s make some order in that.
protected
A protected member is accessible within its class and by derived classes.
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.
* protected internal is the only access modifiers combination allowed for a member or a type.
So, as we 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();
}
}
}
So, if we will try to compile AssemblyB we’ll get an error in line 23 that says : AssemblyA.A.SomeProtectedInternalMethod()’ is inaccessible due to its protection level
I hope this explains once and for all the meaning of “protected internal” access modifier.
A few posts you might find interesting:

Simple & great explanation,Thanks!
Great article. Thank you.
Simply speaking ….
Protected internal Removing restriction of one another and hence come out with different accessibility specifier .
Means..protected provide accessibility outside the assembly also..
& internal provide accessibility to any class within the assembly even it is not derived from the mention class ..
One can’t say, the use of protected internal is redundant…
because its a different accessibility specifier than public,private, internal,protected..(just match)..:)
Good and simple explanation
Thanks
Sathya
Both Protected and ProtectedInternal members can be accessed outside the assembly by
inheriting the contained Class.
internal – can be accessed with in the assembly anywhere by Inheriting/Creating instance.
protected – can be accessed only by Inheriting with in the Assembly/Outside the Assembly.
ProtectedInternal – can be accessed with in the assembly anywhere by Inherting/Creating instance AND accessed outside the assembly by only Inherting the Contained Class
so protectedInternal behaves like both protected or internal.
Thanks
Suresh Raj
nice presentation