2 回答

TA贡献1851条经验 获得超5个赞
不可以,您不能将基本属性的类型更改为返回不同的(派生的)类型。
如果不需要继承,则采用标准解决方法-通用类:
public class ParentClass<T> {
public T ItemValue { get; set; }
...
}
public class ChildClass : ParentClass<ChildClass>
{
...
}
请注意,如果您只需要访问自己类中的item,则可以拥有virtual属性:
public class Parent { }
public class Child:Parent { public string ChildProperty; }
public abstract class ParentClass
{
public abstract Parent ItemValue { get; }
}
public class ChildClass : ParentClass
{
Child item;
public override Parent ItemValue { get {return item;} }
public void Method()
{
// use item's child class properties
Console.Write(item.ChildProperty);
}
}
- 2 回答
- 0 关注
- 205 浏览
添加回答
举报