Whole enum iteration
foreach (Suit suit in Enum.GetValues(typeof(Suit)))
{
// ...
}
But how To iterate a bitwise enum Instance?
Suit mySuits = Suit.Hearts | Suit.Diamonds;
// How to now iterate mySuits, which should loop twice instead of four times?
Assuming
Suitis a bitwise enum with no overlapping values, then this would be sufficient:If it needs to be fast, or if it needs to ignore composite values or a zero value, then you should probably instead check successive powers of two in a
forloop and identify which values match that way.