How to enumerate an enum

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

    foreach (Suit suit in Enum.GetValues(typeof(Suit)))
    {
    }
    

    (The current accepted answer has a cast that I don't think is needed (although I may be wrong).)

提交回复
热议问题