C#:访问修饰符 Access Modifier

共有5个访问修饰符:public, private, protected, internal, protected internal

类本身有2道防线,一是命名空间(namespace),另一个是程序集(Assembly)。

成员则有3道防线,一是类,另外两个同类一样。

而访问修饰符则是类或成员走向外界的一把钥匙。

类存在于命名空间之下,只能为 public 或 internal修饰,默认为internal

成员则可以有5个访问修饰符,但默认为private, 默认遵循最小权利原则

 

The accessibility of the member cannot be greater than the type.

User-defined operators must always be declared as public.

Interface members are always public because the purpose of an interface is to enable other types to access a class or struct. No access modifiers can be applied to interface members.

Enumeration members are always public, and no access modifiers can be applied.

转载于:https://www.cnblogs.com/dmgactive/archive/2011/06/07/2074660.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值