How can I convert an enumeration into a List?

后端 未结 7 1160
难免孤独
难免孤独 2021-01-30 10:31

i have an asp.net-mvc webpage and i want to show a dropdown list that is based off an enum. I want to show the text of each enum item and the id being the int value that the en

相关标签:
7条回答
  • 2021-01-30 11:00

    Now I used Tuple<string, string> but you can convert this to use anything:

    var values = Enum.GetValues(typeof(DayOfWeek))
        .Cast<DayOfWeek>()
        .Select(d => Tuple.Create(((int)d).ToString(), d.ToString()))
        .ToList()
    
    0 讨论(0)
提交回复
热议问题