Protected Internal Access Modifier in C#

Protected Internal Access Modifier in C#
Rating: 5 - 1 Votes

Protected Internal Access Modifier in C#

C#As you know, if you want to make your class reusable in other projects, then you can create a class library and add a reference to it in your projects.  However, which members are accessible and which are not, it all depends upon access modifiers.   Protected Internal is one of the access modifiers where you can make a base class member accessible through derived class only in other projects.  This access modifier is pretty much similar to Protected access modifier.

A class member which is marked as Protected, can be accessible within the same project through derived class.

A class member which is marked as Protected Internal, can be accessible in other projects by providing reference to its class library and using that class as a base class.

The only point to remember here is, after adding reference to class library, you must use using directive on top of your code.   Otherwise, you will get an error.  To access Protected Internal member, there are 2 ways.

  • Create an instance of derived class to access that member.
  • Use base keyword to access that member.