CodeSteps

Python, C, C++, C#, PowerShell, Android, Visual C++, Java ...

C# – Access Modifiers – internal and protected internal access modifiers

C# provides different access modifiers to allow to define the scope for the classes and it’s members. We already discussed few of the modifiers in our previous Articles. In this Article, we will go through internal and protected internal access modifiers.

internal Access Modifier

internal access modifier in C# restricts the access of classes and it’s members to access within the namespace and it’s assembly only where they are defined.

If we do not specify any access modifier, by default it is internal. The members defined with this access specifier can access only with in the namespace and the assembly where the namespace is defined.

protected internal Access Modifier

Another variation of internal access modifier is, protected internal access modifier; which defines additional restriction to the classes and it’s members to allowed to access them within the derived classes.

C# doesn’t allow us to create the class within the namespace with this modifier. If we try to create, C# compiler will throw the below Error message.

Elements defined in a namespace cannot be explicitly declared as private, protected, or protected internal

The members of both these access modifiers are NOT ALLOWED to access outside of it’s assembly.

We will discuss more topics in upcoming Articles.

(Raju)

C# – Access Modifiers – internal and protected internal access modifiers

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top