C# Iterating through an enum? (Indexing a System.Array) -


I have the following code:

  // Get the string name of all the elements Enum string [] within names = Enum.GetNames (typeof (myEnum)); // Get the value of all the elements of my name and values ​​= Enum.GetValues ​​(typeF (myEnum)); // To print names and values ​​(int i = 0; i & lt; names.Length; i ++) {print (name [i], value [i]); }  

However, I can not point the values, is there any easier way to do this?

Or I've completely lost something!

  array value = enum .GetValues ​​(typeof (myEnum)); Foreign Currency (Myanm Values ​​in Values) {Console.WriteLine (String.Format ("{0}: {1}", Enum.GetName (Typf (MyOnum), Val), WAL)); }  

Or, you can remove the system. The following is returned:

  string [] names = Enum.GetNames (typeof (MyEnum)) ; MyEnum [] value = (MyEnum []) Enum.GetValues ​​(typeof (MyEnum)); For (int i = 0; i & lt; names.Length; i ++) {print (name [i], value [i]); }  

But, can you make sure that GetValues ​​give value in the same order because GetNames gives names?


Comments