开发者

What does Protected Internal mean in .Net [duplicate]

This question already has answers here: What is the difference between 'protected' and 'protected internal'? (12 answers) Closed 8 years ago.

Protected Means, we can access this member only in a deriving class, and internal means we can access this member in any type in the same assembly using a object. So can I consider a Protected Internal member as a public member in the same assembly. and as a protected member in the different assembly.

EDIT:

namespace pracConsole
    {
class Class1
{
    protected internal int val;
    public int hello()
    {
        Console.WriteLine("This is method pracConsole.hell开发者_开发问答o");
        Console.ReadLine();
        return 1;

    }
}
class program
{
    static void Main(string[] args)
    {
        Class1 _class1 = new Class1();
        _class1.val = 3;
        _class1.hello();
        Console.ReadLine();
    }
}

}

See I am able to access, protected internal in a non deriving class...so its working as public in same assembly..what do you say.


It's a confusing one.

protected means "only this class and derived classes".

internal means "only classes in this assembly".

protected internal means "protected OR internal" (any class in the same assembly, or any derived class - even if it is in a different assembly).

i.e. it does not mean "protected AND internal" (only derived classes within the same assembly).


Internal means that only classes within the same assembly can access that member

Protected means the member can only be accessed by a deriving type (child class accessing a super class).

Protected internal is a combonation of both of them. It can only be accessed within the same assembly and it can only be accessed as a child class.

More simply: 'protected internal' means 'protected or internal' - this means that it can be accessed within the same assembly or by a deriving type.


Protected internal means that only derived types and types in the same assembly can access the member. It's strange, but it's a union relationship. Meaning, the member can be accessed by anything that can access members marked as internal OR protected.


Not really. The Protected keyword in the declaration statement specifies that the elements can be accessed only from within the same class, or from a class derived from this class. So you can access it from the same library but not from all classes.

And you cannot access Protected Internal from any other library because Internal means access only from the same assembly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜