【发布时间】:2013-02-21 06:50:01
【问题描述】:
我有一个如下界面
public interface I1
{
public int add(int a , int b);
public int subtract (int a, int b);
}
public class Myclass : I1
{
//here I can access both the methods of interface I1
//add and subtract but i want to expose only add not subtract method
//How can I achieve this?
}
我怎样才能只暴露特定的方法并阻止其他方法。
【问题讨论】:
-
你不能阻止它,但是你可以用Explicit interface implementations“隐藏”类型
Myclass(但不是类型I1)上的方法:“显式接口成员实现只能通过接口实例访问,并且在这种情况下仅通过其成员名称引用。"