这里有一个非常简单的例子。
public interface IMyInterfaceProperty
{
}
public class MyProperty : IMyInterfaceProperty
{
}
public interface IMyInterface
{
IMyInterfaceProperty SomeProperty { get; set; }
}
public class MyClass : IMyInterface
{
public MyProperty SomeProperty { get; set; }
}
在这个例子中,
MyProperty
是从 IMyInterfaceProperty
派生而来的,但是不被允许。背后的思考过程是什么导致不能编译通过?
Program.MyClass
没有实现接口成员 Program.IMyInterface.SomeProperty
。因为它没有匹配的返回类型 Program.IMyInterfaceProperty
,所以 Program.MyClass.SomeProperty
无法实现 Program.IMyInterface.SomeProperty
。
T SomeProperty { get; set; }
- the_joric