In C#, do enum flags have to be sequential? or can you leave gaps? and still perform bit-wise comparisons? ie, can you do the following:
[Flags]
public enum MyEnum
{
None = 0,
IsStarred = 1,
IsDone = 128
}
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.
There is nothing wrong with the code you have posted. This is absolutely fine:
And so is this:
Just remember that the
FlagsAttributedoes not enforce your values to be bit masks.