有关私人课程的详细解释吗? [英] Any please explain detail about private class?

查看:78
本文介绍了有关私人课程的详细解释吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只有嵌套类是私有的,或者我们是否在开始时作为私有类初始化并继续我们的程序???

详细解释我



我尝试了什么:



我见过很多例子,但我找不到确切的ans

only nested class is private or whether we initialize at start as private class and continue our program???
Explain me in detail

What I have tried:

I have seen many examples but I couldn't find exact ans

推荐答案

没有。如果您尝试将非嵌套类声明为private,protected或protected internal,则会出现编译器错误:
No. If you try to declare a non-nested class as private, protected, or protected internal you will get as compiler error:
Namespace elements cannot be explicitly declared as private, protected or protected internal



为什么?因为它不会提供有意义的保护级别。

私有意味着该成员只能在包含的类中访问 - 它不能在它之外使用。由于顶级类没有包含类,因此它不能有意义地保密。

如果类嵌套在现有类中,则只能将类声明为私有,然后嵌套类才可用在其包含的类中。


Why? Because it would provide no meaningful level of protection.
Private means that the member is only accessible in the containing class - it can't be used outside it. Since a top-level class has no containing class, it cannot meaningfully be private.
You can only declare a class as private if it is nested within an existing class, and then the nested class is only available within its containing class.


这篇关于有关私人课程的详细解释吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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