If I want to convert between two Enum types, the values of which, I hope, have the same names, is there a neat way, or do I have to do it like this:
enum colours_a { red, blue, green }
enum colours_b { yellow, red, blue, green }
static void Main(string[] args)
{
colours_a a = colours_a.red;
colours_b b;
//b = a;
b = (colours_b)Enum.Parse(typeof(colours_b), a.ToString());
}
?
If you have strict control over the two enum’s, then your solution (or Randolpho’s) is fine.
If you don’t, then I’d skip trying to be tricky and create a static mapping class that converts between them. In fact, I’d probably recommend that anyway (even if you map by name there for now), from an ease-of-maintenance perspective.