I can't select between two methods of converting. What is the best practice by converting from enum to int
1:
public static int EnumToInt(Enum enumValue)
{
return Convert.ToInt32(enumValue);
}
2:
public static int EnumToInt(Enum enumValue)
{
return (int)(ValueType)enumValue;
}
Answer
In addition to @dtb
You can specify the int (or flag) of your enum by supplying it after the equals sign.
enum MyEnum
{
Foo = 0,
Bar = 100,
Baz = 9999
}
Cheers
No comments:
Post a Comment