CSharp中的可访问性 [英] accessability in CSharp

查看:149
本文介绍了CSharp中的可访问性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



请看下面的代码...

Hi,
please see the below code...

public class A{
    public void method1() { }
    public void method2() { }
    public void method3() { }        
    public void method4() { }
}   
public class B:A{}
public class C:A{}



现在我想只有当我创建B类对象时才能访问method1和method2,同样只有method3和method4应该可以访问当我创建C类对象时可以访问。我需要什么o实现这种情况??


now I want that only method1 and method2 should be accesible when I create the object of class B and same way only method3 and method4 should be accesible when I create the object of class C. what I need to do to achive this scenario??

推荐答案

请从这里开始:

http://msdn.microsoft.com/en-us/library/ms173121.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/wxh6fsc7.aspx [ ^ ]。



提供比实际需要更多的访问权限。如果您只在同一个程序集中使用此类型,则每个 public 都可以替换为 internal 。等等...



-SA
Please start here:
http://msdn.microsoft.com/en-us/library/ms173121.aspx[^],
http://msdn.microsoft.com/en-us/library/wxh6fsc7.aspx[^].

Better don't give more access than it's really needed. Every public can be replaced with internal if you are using this type only in the same assembly. And so on…

—SA


这篇关于CSharp中的可访问性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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