【发布时间】:2021-10-01 07:19:42
【问题描述】:
我们如何在类中实现两个或多个具有相同方法名称的接口,并且派生类应该进一步继承到具有相同方法的新类中。
using System;
interface A
{
void Hello();
}
interface B
{
void Hello();
}
class Test : A, B
{
void A.Hello()
{
Console.WriteLine("Test Hello-A");
}
void B.Hello()
{
Console.WriteLine("Test Hello-B");
}
}
class Demo : Test {
//what will be the code to override Hello method
}
public class MainClass
{
public static void Main()
{
//How can we access the Hello method of Test & Demo class
}
}
【问题讨论】:
-
小修正:你不继承接口;你实现它们。
-
问题是什么?你想覆盖什么代码?
-
@OlivierRogier 这不是在回答这个问题,因为这里有一个更复杂的案例,因为
Demo类及其需求。但这绝对是有帮助的。
标签: c# inheritance interface overriding