How can I get the enum value if I have the enum string or enum int value. eg: If i have an enum as follows:
public enum TestEnum
{
Value1 = 1,
Value
I think you forgot the generic type definition:
public T GetEnumValue(int intValue) where T : struct, IConvertible // added
and you can improve it to be most convinient like e.g.:
public static T ToEnum(this string enumValue) : where T : struct, IConvertible
{
return (T)Enum.Parse(typeof(T), enumValue);
}
then you can do:
TestEnum reqValue = "Value1".ToEnum();