Using an enum as an array index in C#

前端 未结 10 937
死守一世寂寞
死守一世寂寞 2020-12-28 14:17

I want to do the same as in this question, that is:

enum DaysOfTheWeek {Sunday=0, Monday, Tuesday...};
string[] message_array = new string[number_of_items_at         


        
10条回答
  •  温柔的废话
    2020-12-28 14:22

    If the values of your enum items are contigious, the array method works pretty well. However, in any case, you could use Dictionary (which is less performant, by the way).

提交回复
热议问题