可以从两个接口为同名方法实现一个实现吗?
我坚信我们需要始终执行显式实现IFoo1.Bar()
,但是下面的代码正在编译和运行。有什么想法吗?
using System;
namespace ConsoleApp1
{
interface IFoo1
{
void Bar();
}
interface IFoo2
{
void Bar();
}
class Foo : IFoo1, IFoo2
{
public void Bar()
{
Console.WriteLine("Test");
}
}
public class Program
{
public static void Main(string[] args)
{
Foo foo = new Foo();
foo.Bar();
IFoo1 iFoo1 = new Foo();
iFoo1.Bar();
IFoo2 iFoo2 = new Foo();
iFoo2.Bar();
}
}
}