Rebar
클래스가 Reinforcement
클래스에서 파생되고 RebarShape
클래스가 ReinforcementShape
클래스를 상속하는 경우 C# 코드에서. 기본 클래스의 ReinforcementShape
속성을 RebarShape
클래스로 재정의 할 수 있습니까?파생 클래스가있는 기본 클래스의 재정의 속성
public class ReinforcementShape
{
}
public class RebarShape : ReinforcementShape
{
}
public class Reinforcement
{
public ReinforcementShape Shape { get; set; }
}
public class Rebar : Reinforement
{
// I want to override the Shape property
// but with its derived class which is RebarShape
// override the base property somehow!
public RebarShape Shape { get; set; }
}
업데이트 :
현재 구현 어떤 문제가 있습니까? 기본에서
:
public virtual ReinforcementShape Shape { get; set; }
파생에서 :
public new RebarShape Shape { get; set; }
속성을 무시하고 반환 유형을 변경할 수 없습니다. –