怀疑C#中的访问说明符 [英] Doubt about access specifiers in C#

查看:69
本文介绍了怀疑C#中的访问说明符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我们不能使用保护和受保护的内部说明符前缀类名

Why can't we use protected and protected internal specifiers prefixing class name

推荐答案

根级别类,即直接在命名空间下的类,可以是内部的或公开的。默认情况下,如果未指定访问修饰符,则它们是内部的。



其他类(嵌套类)中定义的类可能会被声明为受保护。



为什么不能你用保护?保护良好意味着对象可以被声明类型的成员访问,因为根类没有声明类型,它们不能受到任何保护。在你得到我刚才描述的概念后,protected internal没有任何意义。
Root level classes, that is classes directly under a namespace, can either be internal or public. By default if you don't specify an access modifier, they are internal.

Classes defined inside other classes (nested classes) may be declared protected.

Why can't you use protected? Well protected means that the object is accessible to members of its declaring type, since root classes don't have a declaring type, they can't be protected from anything. "protected internal" doesn't make any sense after you get the concept I just described.


这篇关于怀疑C#中的访问说明符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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