命名空间外的私有类 [英] private class outside namespace

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

问题描述

我想在命名空间之外创建一个类,使其默认访问修饰符为PRIVATE".我是这样做的:

I want to create a class outside a namespace so that its default access modifier is 'PRIVATE'. I am doing like this:

namespace KnowStructs
{
    class Clas1 {}
}

class MyClass {}

但是当我查看 Reflector 时,我的类 'MyClass' 仍然被称为内部类.谁能帮帮我.

But still my class 'MyClass' is referred as Internal when I look in Reflector. Can anyone help me out.

推荐答案

如果允许私有类不是嵌套类型,那意味着什么?如果它比 internal 限制更多,那么您将如何使用它或创建一个实例.任何用例都要求它至少是 internal.我想看看你打算如何使用它.

If a private class is allowed that is not a nested type then what would that mean? If it is more restrictive than internal then how would you use it or create an instance. Any use case will require it to be internal at a minimum. I would like to see how you intend to use it.

这完全没有逻辑意义.

而具有私有嵌套类将自身作用域到包含类的父级.如果它是 internal 那么你仍然可以在程序集中创建一个实例.

Whereas having a private nested class scopes itself to the parent containing class. If it were internal then you still will be able to make an instance within the assembly.

因此,对于没有修饰符的类,对于非嵌套类型默认是 internal ,对于嵌套类型是 private ,因为 .Net 在没有指定修饰符时总是应用最严格的访问.

So for classes having no modifier is internal by default for non nested types and private for nested types as .Net always applies the most restrictive access when no modifier is specified.

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

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