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.


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
1. class A3 : A
Class A3 don’t have to inherit from A in your example. If it does, then you can access protected members even on another instance, like this:
A AI = new A();
return ((A3)AI).SomeProtectedInternalMethod();
Within or outside of an assembly in which class A is declared.
2. // We can access the method through an instance
// of the class because it’s internal
Not exactly right. We can access it just because it is in the same assembly.
The point is that you don’t need to declare class A3 as internal (as you did), this has absolutely nothing to do with the access to class A internal members.
@Artem
Hi, Artem
1. You are correct that we don’t have to inherit A3 from A to be able access SomeProtectedInternalMethod from the same assembly (thanks for noticing, probably just mistyped it), but you are wrong about using ((A3)AI).SomeProtectedInternalMethod() within or outside of an assembly in which class A is declared. You indeed can use it using casting but in the SAME assembly only.
2. You can’t access a method in some class just because the class is in the same assembly.
For example if the method was defined as “protected string SomeProtectedInternalMethod()” or just “string SomeProtectedInternalMethod()” you wouldn’t be able to access it even in the same assembly because in case of protected you must inherit the class and in the second case it’s just private for the same class.
@Xander
1. Actually I was wrong because you can’t cast A to A3.
2. I misinterpret your comment. What I meant is that class A3 can access SomeProtectedInternalMethod of class A because SomeProtectedInternalMethod is internal in class A and A3 is in the same assembly. But you made class A3 internal too, and it sounds like you are saying THIS is the reason why it can access the method. But you are not.
if I compile your code I am Not getting any error it is compiling fine….. So I did not understand
I dont know where I am going wrong
Important point:
For example if u define a method as:
protected internal void DoSomething()
{
Console.WriteLine(“I’m Doing…”);
}
Normally, you think this method is protected and internal!!!! <—- THIS IS WRONG !!!!!
The connection between them is OR = protected internal means protected OR internal
Example for that if you define an internal property and you try to set the setter or the getter as protected internal you will get a restrictive error because The union of protected and internal accessibility is less restrictive than protected or internal alone.
Great Article
Really Good . in simple word you explain every thing