How to enumerate an enum

后端 未结 29 1899
深忆病人
深忆病人 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:40

    I know it is a bit messy, but if you are fan of one-liners, here is one:

    ((Suit[])Enum.GetValues(typeof(Suit))).ToList().ForEach(i => DoSomething(i));
    

提交回复
热议问题