How to convert between Enums where values share the same names ?
- by Ross Watson
Hi,
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());
}
Thanks,
Ross