How to convert between Enums where values share the same names ?
Posted
by Ross Watson
on Stack Overflow
See other posts from Stack Overflow
or by Ross Watson
Published on 2010-04-22T15:49:22Z
Indexed on
2010/04/22
15:53 UTC
Read the original article
Hit count: 534
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
© Stack Overflow or respective owner