我有具有抽象属性的基类。我希望所有继承类都覆盖抽象属性。例子:
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 属性。我Someone
在我的TestClass
. 现在我想使用Employee
type 而不是Person
. 我的Employee
类继承自Person
. 我无法让它工作。我应该怎么做才能避免这个问题?
帮助表示赞赏!