简体   繁体   English

覆盖子类C#中的基础抽象类的属性的一部分

[英]Override set part of a property from base abstract class in the subclass C#

I have an abstract class A as my base class from which class B derives. 我有一个抽象类A作为基础类,而类B是从该类派生的。 How can I override the set of DrawingType property in the sub-class B . 如何覆盖子类B中DrawingType属性set

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.
}

Your classes should look like the following: 您的课程应如下所示:

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
        }
    }
}

If the base class doesn't have an implementation you can use 如果基类没有实现,则可以使用

abstract class A
{
    protected DrawingType m_type;

    protected abstract DrawingType Type { get; set; }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM