I have searched this online, but I can't find the answer I am looking for.
Basically I have the following enum:
public enum typFoo : int { itemA : 1, itemB : 2 itemC : 3 }
How can I convert this enum to Dictionary so that it stores in the following Dictionary?
Dictionary<int,string> myDic = new Dictionary<int,string>();
And myDic would look like this:
1, itemA 2, itemB 3, itemC
Any ideas?
Try:
var dict = Enum.GetValues(typeof(fooEnumType)) .Cast<fooEnumType>() .ToDictionary(t => (int)t, t => t.ToString() );
See: How do I enumerate an enum in C#?
foreach( typFoo foo in Enum.GetValues(typeof(typFoo)) ) { mydic.Add((int)foo, foo.ToString()); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With