在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
C#中public、private、protected、internal、protected internal & (2010-09-22 13:33:45)转载 标签: 杂谈 分类: C#
在C#语言中,共有五种访问修饰符:public、private、protected、internal、protected internal。作用范围如下表: using System; using System.Collections.Generic; using System.Text; namespace AccessModifier { public class AccessModifierClass { public string GetPublicString() { return "Public String"; } protected string GetProtectedString() { return "Protected String"; } private string GetPrivateString() { return "Private String"; } internal string GetInternalString() { return "Internal String"; } protected internal string GetProtectedInternalString() { return "Protected Internal String"; } void AvailableAccessModifier() { this.GetPublicString(); this.GetPrivateString(); this.GetInternalString(); this.GetProtectedInternalString(); this.GetProtectedString(); } } public class TestAccessModifierClass1 { void AvailableAccessModifier() { AccessModifierClass item = new AccessModifierClass(); item.GetPublicString(); item.GetInternalString(); item.GetProtectedInternalString(); } } public class TestAccessModifierClass2 : AccessModifierClass { void AvailableAccessModifier() { AccessModifierClass item = new AccessModifierClass(); item.GetPublicString(); item.GetInternalString(); item.GetProtectedInternalString(); base.GetProtectedString(); } } } AccessModifierClass是我们的访问修饰符类,里面有五种访问修饰符方法,可见在AccessModifierClass类里面的AvailableAccessModifier()方法可以访问所有的方法。
|
请发表评论