I have the following enum:
[Flags]
public enum Permissions
{
None = 0x0000,
All = 0xFFFF
}
If either None or All are raised, no other flag should be raised.
How do I check if either None or All are raised and nothing else?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In a flags enum,
Noneshould be zero, andAllshould be the cumulative bitwise sum. This makes the maths pretty easy, then:maybe written as a
switchif you prefer…However, in the general case, you can test for a complete flags match (against any number of bits) with:
and to test for any overlap (i.e. any common bits –
wantedneeds to be non-zero):