Advertisement
Intermediate C# Programming, Access Modifiers in C#

What do protected internal access modifiers mean?

Short answer

The protected internal access modifier combines the rules of protected and internal using an or relationship, meaning a member marked this way is accessible from anywhere within the same assembly, just like internal, as well as from any derived class even if that derived class…

Save C# Programming mock interview
Advertisement
AModel answer
The protected internal access modifier combines the rules of protected and internal using an or relationship, meaning a member marked this way is accessible from anywhere within the same assembly, just like internal, as well as from any derived class even if that derived class exists in a completely different assembly, just like protected. This gives broader access than either protected or internal alone would provide on its own.
public class BaseClass {
    protected internal void Configure() {
        // accessible within the same assembly OR from derived classes anywhere
    }
}
Real-world example
A shared library exposes a configuration method as protected internal, allowing other classes within the same library to call it freely while also allowing external applications that inherit from the base class to access it through their own derived classes.
Likely follow-ups
  • How does protected internal differ from the newer private protected modifier?
  • When would you choose protected internal over plain protected or plain internal?
Related topics