Difference between Internal and Protected Internal in C# .Net

Last Reply 7 months ago By pandeyism

Posted 7 months ago

what i know:

Internal:
The type or member can be accessed by any code in the same assembly but not from another assembly.

Protected Internal:
The type or member can be accessed by any code in the same assembly or by derived class of another assembly.

Can anyone explain me this with simple example code.I found this access modifiers bit confusing.So tried to find the simple example code to make it understand but dint find..

Any help will be appreciated.

Posted 7 months ago

Hey chetan,

Please refer below explaination and link.

Internal :

Internal Member of a class is available or access within the assembly either creating object or in a derived class or you can say it is accessible across all the classes within the assembly.

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/internal

Protected Internal :

A protected internal member of a base class is accessible from any type within its containing assembly. It is also accessible in a derived class located in another assembly only if the access occurs through a variable of the derived class type.

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/protected-internal