Most C# devel­op­ers will know what “pub­lic”, “pri­vate”, “pro­tected” and “inter­nalaccess mod­i­fiers mean and would have had to use them in their code, but rarely do we come across the “pro­tected inter­nal” access modifier.

Now, pro­tected means the type or mem­ber can be accessed by derived classes, NOT restricted to the same assem­bly, whereas inter­nal means the type or mem­ber can be accessed by code ONLY in the same assem­bly. It’s easy (and com­mon) to think of the access mod­i­fiers in a lin­ear sense where pri­vate is the most restric­tive, and pro­tected, inter­nal and ulti­mately pub­lic becomes less and less restrictive:

image

This is cer­tainly the case within the SAME assem­bly, but when you have mul­ti­ple assem­blies this no longer holds true as types might be derived out­side of the assem­bly it’s declared in:

image

And that is what pro­tected inter­nal gives you – acces­si­bil­ity from any derived classes any­where, as well as any class from within the same assembly.

Share

Leave a Reply