How to enumerate an enum

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

    public void PrintAllSuits()
    {
        foreach(string suit in Enum.GetNames(typeof(Suits)))
        {
            Console.WriteLine(suit);
        }
    }
    

提交回复
热议问题