c# - you cannot declare private, protected, protected internal directly in NS

本文讨论了C#中私有类定义的问题,并解释为何不能在命名空间根目录下定义私有类。文章指出,C#编译器限制了这种用法,因为类默认就是私有的,同时命名空间本身并不提供访问控制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

namespace enumInXamldemo
{
    private class AClass
    {
        
    }
}

 with the simple class definiiton, is there any problem with it? 

 

yes, you cannot compile it, the C# compiler has made a step forward in making the some misleading access modifier invalid in some applications. 

 

so it does not make sense to make a private class inside a namespace root because 1. by default the class definition is private, and 2. namespace does not have access control, you cannot say this class is pirvate inside this namespace, it only provide a name management ability ,but it does not control how the accessiblity is, because the accessiblity is specificed on the assembly level..

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值