我有这样的代码:
public interface INode
{
INode Parent { get; set; }
// ......
}
public interface ISpecificNode : INode
{
new ISpecificNode Parent { get; set; }
// ......
}
public class SpecificNode : ISpecificNode
{
ISpecificNode Parent { get; set; }
// ......
}
这段代码给出了一个编译错误,因为 INode.Parent 没有实现。但是,我不需要重复的父属性。
我该如何解决这个问题?
最佳答案
我认为您正在寻找这样的东西:
public interface INode<T> where T : INode<T>
{
T Parent { get; set; }
}
public interface ISpecificNode : INode<ISpecificNode>
{
}
public class SpecificNode : ISpecificNode
{
public ISpecificNode Parent { get; set; }
}
关于c# - C#中的接口(interface)多态性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19207362/