According to my code a=1, b=2, c=3 etc. I thought the flag would make a=1, b=2, c=4, etc
[Flags]
public enum someEnum { none, a, b, c, d, e, f, }
How do i get what i intended(c=4, e=8)? and what does the [Flags] mean above?
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.
You can specify values for the enums, this is needed for flags cases:
It means the runtime will support bitwise operations on the values. It makes no difference to the values the compiler will generate. E.g. if you do this
with the Flags attribute the result of
x.ToString()is “Alpha, Beta“. Without the attribute it would be 3. Also changes parsing behaviour.EDIT: Updated with better names, and the compiler doesn’t complain using bitwise ops on a non-flags attribute, at least not C#3 or 4 (news to me).