这个标题是不是很拗口?...
这是我正在尝试做的事情:
public interface IBar {
void Bar();
}
public interface IFoo: IBar {
void Foo();
}
public class FooImpl: IFoo {
void IFoo.Foo() { /* works as expected */ }
//void IFoo.Bar() { /* i'd like to do this, but it doesn't compile */ }
//so I'm forced to use this instead:
void IBar.Bar() { /* this would compile */ }
}
我的问题是……调用 Bar() 很不方便:
IFoo myFoo = new FooImpl();
//myFoo.Bar(); /* doesn't compile */
((IBar)myFoo).Bar(); /* works, but it's not necessarily obvious
that FooImpl is also an IBar */
所以......有没有办法IFoo.Bar(){...}
在我的类中声明,而不是基本上将两个接口合并为一个?
如果不是,为什么?