No, you don’t want a generic method. This is much easier:
MyEnum myEnum = (MyEnum)myInt;
MyEnum myEnum = (MyEnum)Enum.Parse(typeof(MyEnum), myString);
I think it will also be faster.
More Related Contents:
- Create Generic method constraining T to an Enum
- Getting attributes of Enum’s value
- String representation of an Enum
- JavaScriptSerializer – JSON serialization of enum as string
- Enum ToString with user friendly strings
- Get Enum from Description attribute [duplicate]
- How to loop through all enum values in C#? [duplicate]
- Most common C# bitwise operations on enums
- Enum type constraints in C# [duplicate]
- How to iterate over values of an Enum having flags?
- Enum String Name from Value
- Get enum from enum attribute
- How do I convert an enum to a list in C#? [duplicate]
- How do I cast int to enum in C#?
- C# Iterating through an enum? (Indexing a System.Array)
- How to Compare Flags in C#?
- When to use enums, and when to replace them with a class with static members?
- How to TryParse for Enum value?
- Extension method on enumeration, not instance of enumeration
- How do I cast a generic enum to int?
- How do I select a random value from an enumeration?
- Validate Enum Values
- How do I have an enum bound combobox with custom string formatting for enum values?
- How to get next (or previous) enum value in C#
- convert an enum to another type of enum
- Choosing the default value of an Enum type without having to change values
- C# Enum – How to Compare Value
- Why Enum’s HasFlag method need boxing?
- Can you have multiple enum values for the same integer? [duplicate]
- MVC 5.1 Razor DisplayFor not working with Enum DisplayName