What is the best way to "override" enums?

Posted by Tyler on Stack Overflow See other posts from Stack Overflow or by Tyler
Published on 2011-01-16T06:54:06Z Indexed on 2011/01/16 7:53 UTC
Read the original article Hit count: 179

Filed under:
|
|

I have a number of classes which extend an abstract class. The abstract parent class defines an enum with a set of values. Some of the subclasses inherit the parent class's enum values, but some of the subclasses need the enum values to be different. Is there any way to somehow override the enum for these particular subclasses, and if not, what is a good way to achieve what I'm describing?

class ParentClass
{
    private MyEnum m_EnumVal;
    public virtual MyEnum EnumVal
    {
        get { return m_EnumVal; }
        set { m_EnumVal = value; }
    }

    public enum MyEnum { a, b, c };
}

class ChildClass : ParentClass
{
    private MyEnum m_EnumVal;
    public virtual MyEnum EnumVal
    {
        get { return m_EnumVal; }
        set { m_EnumVal = value; }
    }

    public enum MyEnum { d, e, f };
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about inheritance