在c#中实现两个具有相同功能的接口

Apa*_*ran 1 c# interface

我们可以在c#中实现两个具有相同功能的接口吗?

interface TestInterface
{
    public function testMethod();
}

interface TestInterface2
{
    public function testMethod();
}

class TestClass implements TestInterface, TestInterface2
{

}
Run Code Online (Sandbox Code Playgroud)

这可能吗?

我发现这里的 PHP不可能

aqu*_*aga 5

是的,您可以使用接口名称限定方法名称:

    class TestClass : TestInterface, TestInterface2
    {
        void TestInterface.testMethod()
        {

        }

        void TestInterface2.testMethod()
        {
        }
    }
Run Code Online (Sandbox Code Playgroud)

虽然我不建议有这样的结构 - 它应该只是为了学术兴趣:-)