I am trying to write a generic method that can take any enum of type int and be able to convert it to its int value. For example:
public int GetIntValue(Enum enumValue) {
return (int)enumValue;
}
Here is one way that I have accomplished this, but it seems like there is a better way:
public static int ToInt(this Enum value) {
return (int) Enum.Parse(value.GetType(), Enum.GetName(value.GetType(), value));
}
Any ideas?
You mostly had it with example 2 – you should be able to do this: