差异b/w受保护和受保护内部? [英] Difference b/w Protected and Protected Internal ?

查看:94
本文介绍了差异b/w受保护和受保护内部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

在C#中,b/w受保护和受保护内部的确切区别是什么?请帮我举个例子.

谢谢.

Hi All,

What is the exact difference b/w Protected and Protected Internal in C#? Please help me with an example.

Thanks.

推荐答案

两者都是访问修饰符,但与Protected相比,Protected Internal的作用域级别为Internal.

受保护的:该类型或成员只能由相同类或结构中的代码或从该类派生的类中的代码访问. .
在哪里
受保护的内部:类型或成员可以由声明了它的程序集中的任何代码访问,也可以从另一个程序集的派生类中访问 b>.来自另一个程序集的访问必须在从声明受保护内部元素的类派生的类声明中进行,并且必须通过派生类类型的实例进行.

在这里阅读所有您想了解的信息:
MSDN:访问修饰符(C#编程指南) [了解以下语言中的受保护的,内部的和受保护的内部访问修饰符OOPs [ ^ ]
Both are access modifier but Protected Internal has additional scope level of Internal compared to Protected.

protected: 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.
WHERE AS
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. 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.

Read all you want to know about them here:
MSDN: Access Modifiers (C# Programming Guide)[^]
Understanding Protected, Internal and Protected Internal Access modifiers in OOPs[^]


这篇关于差异b/w受保护和受保护内部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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