【发布时间】:2020-04-09 13:55:04
【问题描述】:
interface A {
void method();
}
interface B {
void method();
}
class c : A,B {
//answer
}
【问题讨论】:
-
我们无法在 C# 中实现多重继承。实现多个接口不是多重继承。
标签: c# oop inheritance interface
interface A {
void method();
}
interface B {
void method();
}
class c : A,B {
//answer
}
【问题讨论】:
标签: c# oop inheritance interface
您可以显式地实现接口。
class C : A, B
{
void A.Method()
{
// explicit implementation of interface A
}
void B.Method()
{
// explicit implementation of interface B
}
public void Method()
{
// class implementation
}
}
您应该知道如何调用特定方法。
var c = new C();
c.Method(); // class implementation
((B)c).Method(); // implementation of B
((A)c).Method(); // implementation of A
【讨论】: