How to enumerate an enum

后端 未结 29 2343
深忆病人
深忆病人 2020-11-22 01:14

How can you enumerate an enum in C#?

E.g. the following code does not compile:

public enum Suit
{         


        
29条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 01:45

    Also you can bind to the public static members of the enum directly by using reflection:

    typeof(Suit).GetMembers(BindingFlags.Public | BindingFlags.Static)
        .ToList().ForEach(x => DoSomething(x.Name));
    

提交回复
热议问题