我有一个像下面如何防止暴露其他接口方法?
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 implementation](http://msdn.microsoft.com/en-us/)隐藏“Myclass”类型的方法(但不能键入'I1') library/aa664591(v = vs.71).aspx):“*显式接口成员实现只能通过接口实例*访问,并且在这种情况下仅由其成员名称引用。” – 2013-02-21 07:13:19