Y Yosh Apr 22, 2005 #1 What is the best method to convert an integer to Enum equivelant? I hope this makes sense. Thanks, David
What is the best method to convert an integer to Enum equivelant? I hope this makes sense. Thanks, David
H Hans Kesting Apr 22, 2005 #2 Yosh said: What is the best method to convert an integer to Enum equivelant? I hope this makes sense. Thanks, David Click to expand... cast: MyEnum enumvar = (MyEnum)intvar; Hans Kesting
Yosh said: What is the best method to convert an integer to Enum equivelant? I hope this makes sense. Thanks, David Click to expand... cast: MyEnum enumvar = (MyEnum)intvar; Hans Kesting
M Mythran Apr 22, 2005 #3 Yosh said: What is the best method to convert an integer to Enum equivelant? I hope this makes sense. Thanks, David Click to expand... // Notice the type specifier, int. public enum MyEnums : int { Enum1 = 0, Enum2, Enum3 } ... MyEnum myVar = 1; ... Another way: MyEnum myVar = (MyEnums) 1; ... If you just have the name of the enum value: MyEnum myVar = System.Enum.Parse(typeof(MyEnums), "Enum2"); Hope this helps Mythran
Yosh said: What is the best method to convert an integer to Enum equivelant? I hope this makes sense. Thanks, David Click to expand... // Notice the type specifier, int. public enum MyEnums : int { Enum1 = 0, Enum2, Enum3 } ... MyEnum myVar = 1; ... Another way: MyEnum myVar = (MyEnums) 1; ... If you just have the name of the enum value: MyEnum myVar = System.Enum.Parse(typeof(MyEnums), "Enum2"); Hope this helps Mythran