I have a fairly basic question: How can I check if a given value is contained in a list of enum values?
For example, I have this enum:
public enum UserStatus
{
Unverified,
Active,
Removed,
Suspended,
Banned
}
Now I want to check if status in (Unverified, Active)
I know this works:
bool ok = status == UserStatus.Unverified || status == UserStatus.Active;
But there has to be a more elegant way to write this.
The topic of this question is very similar, but that's dealing with flags enums, and this is not a flags enum.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…