.NET: Create Dictionary from Enums | Convert Enum to Dictionary

5/17/2018 3:39:51 PM

Convert a .NET enum to a dictionary (Dictionary<int, string>);

var enumDictionary = Enum.GetValues(typeof(MyEnum)).Cast<int>().ToDictionary(e => e, e => Enum.GetName(typeof(MyEnum), e));