proteced vs internal vs protected internal

Most C# developers will know what “public”, “private”, “protected” and “internalaccess modifiers mean and would have had to use them in their code, but rarely do we come across the “protected internal” access modifier.

Now, protected means the type or member can be accessed by derived classes, NOT restricted to the same assembly, whereas internal means the type or member can be accessed by code ONLY in the same assembly. It’s easy (and common) to think of the access modifiers in a linear sense where private is the most restrictive, and protected, internal and ultimately public becomes less and less restrictive:

image

This is certainly the case within the SAME assembly, but when you have multiple assemblies this no longer holds true as types might be derived outside of the assembly it’s declared in:

image

And that is what protected internal gives you – accessibility from any derived classes anywhere, as well as any class from within the same assembly.

Enjoy what you’re reading? Subscribe to my newsletter and get more content on AWS and serverless technologies delivered straight to your inbox.


Yan Cui

I’m an AWS Serverless Hero and the author of Production-Ready Serverless. I have run production workload at scale in AWS for nearly 10 years and I have been an architect or principal engineer with a variety of industries ranging from banking, e-commerce, sports streaming to mobile gaming. I currently work as an independent consultant focused on AWS and serverless.

You can contact me via Email, Twitter and LinkedIn.

Hire me.


Check out my new course, Complete Guide to AWS Step Functions.

In this course, we’ll cover everything you need to know to use AWS Step Functions service effectively. Including basic concepts, HTTP and event triggers, activities, design patterns and best practices.

Get Your Copy