我有一个如下所示的界面
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?
}
我怎样才能只公开特定方法并阻止其他方法。
最佳答案
对于这种需求,请选择抽象类而不是接口(interface),因为在接口(interface)中所有方法默认都是公共(public)的,这是抽象类和接口(interface)之间的区别之一。
在interface中不能放private和public这样的修饰符,所有的方法默认都是public的。
关于c# - 如何防止暴露任何其他接口(interface)方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14996215/