如何创建私有类 [英] how to create a private class
本文介绍了如何创建私有类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
正如我们所知,如果我们创建一个私有类,我们会得到以下错误,
命名空间中定义的元素不能显式声明为私有,受保护或受保护的内部。
然后如何创建私人课程。
仅限课堂?(仅限嵌套课程?)
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 aprivate
class as a nested class. If you need the class to be visible only in the assembly, then you create it asinternal
. If you think about it, you will see why you cannot directly create aprivate
class in thenamespace
- that's primarily because you could not instantiate it from outside.
这篇关于如何创建私有类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文