我有一个抽象类 A 作为我的基类,派生类 B 。如何覆盖子类 B set
DrawingType
属性>
public abstract class A
{
protected DrawingType m_type;
public DrawingType Type
{
get { return m_type; }
set { m_type = value}
}
}
public B : A
{
// I want to override the 'set' of DrawingType property here.
}
答案 0 :(得分:0)
您的课程应如下所示:
abstract class A
{
protected DrawingType m_type;
protected virtual DrawingType Type
{
get { return m_type; }
set { m_type = value; }
}
}
class B : A
{
protected override DrawingType Type
{
get
{
return m_type;
}
set
{
m_type = //custom logic goes here
}
}
}
如果基类没有实现,您可以使用
abstract class A
{
protected DrawingType m_type;
protected abstract DrawingType Type { get; set; }
}