Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public enum MyEnum
- {
- One=1,
- Two=2,
- Three=3
- }
- Enum.GetNames(typeof(MyEnum))
- .Select(exEnum =>
- (MyEnum)Enum.Parse(typeof(MyEnum), exEnum))
- .ToList();
- Enum.GetValues(typeof(MyEnum)).Cast<MyEnum>();
- public static class MyGlobals
- {
- public static readonly List<MyEnum> EnumList =
- Enum.GetValues(typeof(MyEnum)).Cast<MyEnum>().ToList();
- }
- public static List<T> EnumToList<T>()
- {
- Type enumType = typeof(T);
- // Can't use type constraints on value types, so have to do check like this
- if (enumType.BaseType != typeof(Enum))
- throw new ArgumentException("T must be of type System.Enum");
- return new List<T>(Enum.GetValues(enumType) as IEnumerable<T>);
- }
Add Comment
Please, Sign In to add comment