How can you enumerate an enum
in C#?
(您如何enum
C#中的enum
?)
Eg the following code does not compile:
(例如,以下代码无法编译:)
public enum Suit
{
Spades,
Hearts,
Clubs,
Diamonds
}
public void EnumerateAllSuitsDemoMethod()
{
foreach (Suit suit in Suit)
{
DoSomething(suit);
}
}
And gives the following compile-time error:
(并给出以下编译时错误:)
'Suit' is a 'type' but is used like a 'variable'
(“西装”是“类型”,但像“变量”一样使用)
It fails on the Suit
keyword, the second one.
(它在Suit
关键字(第二个)上失败。)
ask by Ian Boyd translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…