我有具有抽象属性的基类。我想要所有的继承类来覆盖抽象属性。例如:继承具有抽象属性的抽象类
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
类型。我在TestClass
上压倒Someone
财产。现在我想使用Employee
类型而不是Person
。我的Employee
类继承自Person
。我无法让它工作。我应该怎么做才能避免这个问题?
帮助感谢!
你永远不会实现Person Person,而Employee Employee不在基类MyBase中。 – Matthew
[c#covariant返回类型利用泛型]的可能重复(http://stackoverflow.com/questions/4348760/c-sharp-covariant-return-types-utilizing-generics) – nawfal