如何创建私有类 [英] how to create a private class

查看:82
本文介绍了如何创建私有类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如我们所知,如果我们创建一个私有类,我们会得到以下错误,

命名空间中定义的元素不能显式声明为私有,受保护或受保护的内部。



然后如何创建私人课程。



仅限课堂?(仅限嵌套课程?)

as we know ,if we create a class as private we get folowing error,
Elements defined in a namespace cannot be explicitly declared as private, protected, or protected internal.

then how to create a private class.

with in class only ?(nested classes only ?)

推荐答案

您只能创建一个私有类作为嵌套类。如果您需要仅在程序集中显示该类,则将其创建为 internal 。如果你考虑一下,你就会明白为什么你不能在命名空间中直接创建一个私有类 - 这主要是因为你无法从外面实例化。
You can only create a private class as a nested class. If you need the class to be visible only in the assembly, then you create it as internal. If you think about it, you will see why you cannot directly create a private class in the namespace - that's primarily because you could not instantiate it from outside.


这篇关于如何创建私有类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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