We already know we can convert an enum to another type of enum, so the following compiles:
public class EnumTest
{
enum Enum1 { Foo };
enum Enum2 { Foo };
void Test ()
{
System.Enum e = new Enum2(); // compiles
Enum1 e1 = (Enum1)new Enum2(); // compiles with an explicit cast
}
}
But this doesn't compile:
public class EnumTest
{
enum Enum1 { Foo };
enum Enum2 { Foo };
void Test ()
{
List<System.Enum> eList = new List<Enum2>(); // doesn't compile
List<Enum1> e1List = (List<Enum1>)new List<Enum2>(); // doesn't compile
}
}
Is that a covariance issue? If not, is there a way to make it work?