I just want to know what is the actual difference between private and protected internal access specifier. As i know
Visible to own class members: private and protected internal YES
Visible to object of other classes: Both NO
Visible to objects of other classes outside the namespace collection: Both NO
Visible to object of child classes outside the namespace collection: Both NO
If private doing the same as protected internal then why we need the both just one should be enough or not?
my understanding is that for protected - A protected member is accessible within its class and by derived class instances irrespective of the assembly, whereas for Private protected - A private protected member is accessible by types derived from the containing class, but only within its containing assembly.
Private: - Private members are only accessible within the own type (Own class). Internal: - Internal member are accessible only within the assembly by inheritance (its derived type) or by instance of class.
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.
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.
protected internal
member is visible to any code in the current assembly or in a derived class in another assembly. In technical words, it's the logical disjunction of protected
and internal
.private
member is visible only to code in the same class.protected internal
is actually the second most permissive access modifier after public
.
It's worth noting that protected
is arguably more permissive than internal
, since it allows access from code that you have no control over (i.e. other assemblies). While internal
allows access from all code in the current assembly, this code is yours and you have control over it!
To paraphrase, protected
(and protected internal
) members are part of the public API of your assembly (and should therefore be documented). internal
members are not.
A graphical overview (summary in a nutshell)
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