A base class have readonly field of type List<SomeEnum> which the derived classes will initialize. Now, there is a derived class in which I want to add the all the values of the SomeEnum. One way is to type all the enum values, but the enum is a little big, so is there any other way to do it?
public class Base
{
private readonly List<SomeEnum> _list;
protected Base(List<SomeEnum> list)
{
_list = list;
}
}
public class Derived : Base
{
public Derived() : base(new List<SomeEnum>() { Enum.GetValues(typeof(SomeEnum)) }
{
}
}
(The above code would not compile, I believe intializers don't accept arrays.)
IEnumerable<SomeEnum>orIList<SomeEnum>in the base constructor for future flexibility.