Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a difference between Protected Internal and Internal Protected?

public class TestClass
{
    protected internal int FieldA;
    internal protected int FieldB;    
}

Is there a difference between Protected Internal and Internal Procted Members?

like image 227
RAM Avatar asked Feb 17 '13 23:02

RAM


4 Answers

Is there a difference between protected internal and internal protected members?

There is no difference between them.

protected internal means protected OR internal.

internal protected means internal OR protected.

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. Access from another assembly must take place within a class declaration that derives from the class in which the protected internal element is declared, and it must take place through an instance of the derived class type.

Of the two, protected internal is commonly used. There is no reference to internal protected on the MSDN page about Access Modifiers.

Also check out Phil Haack's blog post What Does Protected Internal Mean?

like image 116
Soner Gönül Avatar answered Sep 29 '22 02:09

Soner Gönül


No, no difference. You can declare them in any order you want. Just like you can declare static before or after the access modifier.

The only real difference should be what you and your team decide on. Typically you'll want to stick to one style to avoid confusion or assumptions, or at least make things consistent when reading it.

EDIT: Though, now that I think of it, I don't recall seeing "internal protected" often. On the MSDN page for access modifiers, it does list it as "protected internal", so maybe stick with that as it may be considered "more standard".

like image 39
Chris Sinclair Avatar answered Sep 29 '22 02:09

Chris Sinclair


No, there is not.

Both variants define a member that is accessible from the same assembly AND from descendant classes.

like image 40
Fyodor Soikin Avatar answered Sep 29 '22 02:09

Fyodor Soikin


it's a bitwise operation with a logical "OR" => Internal : from the same assembly. protected : from a derived class. "protected AND internal" is no sense :-)

like image 43
Stephane Halimi Avatar answered Sep 29 '22 01:09

Stephane Halimi