设计一个类时,能否让其中一些成员只对某些特定类可见?

解决方案 »

  1.   

    可以考虑使用接口来实现:------定义接口及类
    class A : IA
    {
    public void a()
    {
    throw new Exception("The method or operation is not implemented.");
    } void IA.b()
    {
    throw new Exception("The method or operation is not implemented.");
    }
    }
    class B : IA
    {
    void IA.a()
    {
    throw new Exception("The method or operation is not implemented.");
    } public void b()
    {
    throw new Exception("The method or operation is not implemented.");
    }
    }--------使用类--------
    A aa = new A();
    aa.a();//只看到a方法,看不到b方法
    B bb = new B();
    bb.b();//只看到b方法,看不到a方法
      

  2.   

    想不太复杂了嘛!
    访问属性设置成:protected !