“保护”和“受保护的内部'之间的区别是什么? [英] What is the difference between 'protected' and 'protected internal'?

查看:169
本文介绍了“保护”和“受保护的内部'之间的区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能敷衍我'保护'和C#的受保护的内部修饰符之间的区别? 看起来,他们表现得同样的方式。

Can someone please elaborate me the difference between 'protected' and 'protected internal' modifiers in C#? It looks they behave in same manner.

推荐答案

MSDN (点击了解更多信息):

From MSDN (click for more information):

保护

protected:

该类型或成员都可以在同一个类只访问了code或   结构或一类是从该类派生的。

The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class.

内部

internal:

该类型或成员可以通过任何code在同一个组件进行访问,   但不能从另一个程序集。

The type or member can be accessed by any code in the same assembly, but not from another assembly.

受保护的内部

该类型或成员可以通过任何code在装配中进行访问   声明它,或者在派生类中的另一   部件。从另一个程序访问必须在一个类中的地方   声明源自其中保护类   内部元件被声明,它必须通过一个发生   例如派生类类型。

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.


...和完整性:

私人

private

该类型或成员都可以在同一个类只访问了code或   结构。

The type or member can be accessed only by code in the same class or struct.

公共

public

的类型或成员可以通过任何其他code在相同的被访问   装配或引用它的另一个组件。

The type or member can be accessed by any other code in the same assembly or another assembly that references it.

这篇关于“保护”和“受保护的内部'之间的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆