Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between private protected and internal protected [duplicate]

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?

like image 234
Enes Sadık Özbek Avatar asked Jan 12 '18 13:01

Enes Sadık Özbek


People also ask

What is the difference between protected and internal protected?

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.

What is the difference between public/private protected and internal?

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.

Is there any difference between public protection and private protection?

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.

What does private protected mean?

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.


1 Answers

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

like image 145
Ehsan Ullah Nazir Avatar answered Oct 19 '22 15:10

Ehsan Ullah Nazir