【发布时间】:2013-05-16 21:17:53
【问题描述】:
我有具有抽象属性的基类。我希望所有继承类都覆盖抽象属性。示例:
public class Person
{
public string Name{get;set;}
public string LastName{get;set;}
}
public class Employee : Person
{
public string WorkPhone{get;set;}
}
public abstract class MyBase
{
public abstract Person Someone {get;set;}
}
public class TestClass : MyBase
{
public override Employee Someone{get;set;} //this is not working
}
基类具有 Person 类型的 Some 属性。我正在覆盖我的TestClass 上的Someone 属性。现在我想使用Employee 类型而不是Person。我的Employee 类继承自Person。我无法让它工作。我应该怎么做才能避免这个问题?
帮助表示赞赏!
【问题讨论】:
-
你永远不会实现
Person Someone,并且Employee Someone不在基类中(MyBase)。
标签: c# overriding abstract-class type-inference abstract-data-type