There is a listing of the form:

enum MyControls: ulong { elementONE = 18410924985427079801, elementTWO = 88410924985427079804, elementF = 58410924985427079802}; 

There is also an array, which is initiated at startup as follows:

 MyClass[] mc1 = new MyClass[Enum.GetNames(typeof(MyControls)).Length]; 

instances of myclass are added and correspond to the same order as described in mycontrols.

Is it possible to somehow access the elements of such an array using an entry of the form mc1[MyControls.elementF] . (index elementF == 2)

Interested in any ways to get the index in this listing!

It would be possible to get an additional listing, for example

 enum MyControlsNames = {elementONE, elementTWO, elementF } 

and free to write mc1[MyControlsNames.elementF] , but the 1st method is interested.

Thank you for the answers!

  • @Grundy This edit was rejected. Wasn’t "edit (1)" visible? Is this a bug? - 0xdb 2:29 pm
  • @ 0xdb, I could easily start editing earlier and finish later. And also, it seems that at that time I was not editing, but the author of the question. - Grundy
  • @ 0xdb, so there is no lock at all. - Grundy

2 answers 2

Make not an array, but a Dictionary

 var mc1 = new Dictionary<MyControls,MyClass>(); mc1.Add(MyControls.elementF, new MyClass(MyControls.elementF)); 
  • I think this is what you need, thanks! - thez

You can overload the indexer

 class MyClass { public int this[ulong i] { get { // ваш код извлечения необходимой записи } } } 

You can read about overloading indexers here and here .