나는 공통 조상이 다양한 속성을 설정하는 데 관련된 모든 논리를 담당하는 클래스 집합을 만들기 위해 노력하고 있으며 자손은 속성에 대한 액세스를 변경하는지 여부에 따라 그들은 특별한 후손에게 요구된다.속성의 액세스 한정자를 늘리는 방법
내가 컴파일러 오류 얻을 아래와 같이 나는 그것을 할 때 :
" '보호'멤버를 상속 재정의하는 경우 액세스 한정자를 변경할 수 없습니다 것은"나는에 노력하고있어 달성 할 수있는 방법이 있나요을 해야 할 것? 감사합니다
public class Parent
{
private int _propertyOne;
private int _propertyTwo;
protected virtual int PropertyOne
{
get { return _propertyOne; }
set { _propertyOne = value; }
}
protected virtual int PropertyTwo
{
get { return _propertyTwo; }
set { _propertyTwo = value; }
}
}
public class ChildOne : Parent
{
public override int PropertyOne // Compiler Error CS0507
{
get { return base.PropertyOne; }
set { base.PropertyOne = value; }
}
// PropertyTwo is not available to users of ChildOne
}
public class ChildTwo : Parent
{
// PropertyOne is not available to users of ChildTwo
public override int PropertyTwo // Compiler Error CS0507
{
get { return base.PropertyTwo; }
set { base.PropertyTwo = value; }
}
}
OOPS .. 초 빠른 :) .. 어쨌든 새로운 것을 사용하는 것은 오버라이드와 동일하지 않습니다. new는 부모 멤버를 숨기고 더 이상 다형성이 아닙니다. – Galilyou
@ José, 감사합니다. – WileCau