How can I get the max int value from an enum using generics?
I have tried the following however it displays the following compilation error:
Cannot implicitly convert T to int
int maxValue = GetMaxValue<SomeEnum>(typeof(SomeEnum)); //expecting 2
private static int GetMaxValue<T>(Type enumType)
{
return Enum.GetValues(enumType).Cast<T>().Max();
}
public enum SomeEnum
{
ValueOne = 1,
Value = 2
}