-4

I have this simple enum;

public enum MyEnum
{
    FOO = 1,
    BOO = 2,
}

I could use GetValues or GetNames but that excludes the other :-/

fUrious
  • 434
  • 5
  • 14
  • 2
    Possible duplicate of [C# Iterating through an enum? (Indexing a System.Array)](https://stackoverflow.com/questions/482729/c-sharp-iterating-through-an-enum-indexing-a-system-array) – yinnonsanders Sep 12 '17 at 20:55

1 Answers1

2

If I understand your question correctly

var dict = Enum.GetValues(typeof(MyEnum))
           .Cast<int>()
           .ToDictionary(x => Enum.GetName(typeof(MyEnum), x), x => x);
L.B
  • 114,136
  • 19
  • 178
  • 224
  • For enumerating values you can use `Enum.GetValues(typeof(MyEnum)).Cast()`. Also in order for this to work you need to `import System.Linq` – Thomas Devries Sep 12 '17 at 21:10