C# 7.2 introduced the private protected
modifier, whats the difference to internal protected
?
From the doc:
A private protected member is accessible by types derived from the containing class, but only within its containing assembly.
Isn't that exactly what internal protected
does?
protected: The type or member can be accessed only by code in the same class , or in a class that is derived from that class . internal: The type or member can be accessed by any code in the same assembly, but not from another assembly.
public - can be access by anyone anywhere. private - can only be accessed from with in the class it is a part of. protected - can only be accessed from with in the class or any object that inherits off of the class. Nothing is like null but in VB.
Broadly speaking, public means everyone is allowed to access, private means that only members of the same class are allowed to access, and protected means that members of subclasses are also allowed.
The private protected keyword combination is a member access modifier. A private protected member is accessible by types derived from the containing class, but only within its containing assembly. For a comparison of private protected with the other access modifiers, see Accessibility Levels.
From Access Modifiers (C# Programming Guide)
Protected Internal : The type or member can be accessed by any code in the assembly in which it is declared, or from within a derived class in another assembly.
And
Private Protected : The type or member can be accessed only within its declaring assembly, by code in the same class or in a type that is derived from that class.
Another useful link C# 7 Series, Part 5: Private Protected
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With