It's easy. The FlagAttribute makes this enum binary (or a bit field). With that you can now store more than one value into the enum by using the bitwise OR operator |
For example
var adminOnly = UserGroup.Administartor // adminOnly = 8
var moreGroups = UserGroup.Administrator | UserGroup.User // moreGroups = 9
var oneMOre = UserGroup.User | UserGroup.Manager | UserGroup.Supervisor // oneMOre = 7
The enum then also has a method called "HasFlag" to check if a variable contains a certain enum flag.
moreGroups.HasFlag(UserGroup.Manager) // false => 9 - 4 = 5, there is no enum with value 5.
moreGroups.HasFlag(UserGroup.User) // true 9 - 1 = 8 => 8 admin does exist and user so this matches
Answers are yes,yes,no. First yes is because of FlagsAtrribute(see official doc),second yes is trivial, but for last question answer is no because " lt; " doesn't mean nothing in c#. Thats my opninion!!!
upvoted 7 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
mpa
Highly Voted 5 years, 7 months agoStnash
5 years agofounderDev
4 years, 10 months agoslobex
Highly Voted 4 years, 6 months agomerry
Most Recent 3 years, 10 months agoDaGrooveNL
3 years, 10 months agoruif90
4 years, 3 months agokurokyuu
4 years, 2 months agoHgstExam
4 years, 3 months agoHgstExam
4 years, 3 months agoMultima
4 years, 10 months agoMultima
4 years, 10 months agofounderDev
4 years, 10 months agojose1024
4 years, 11 months agomaly007
5 years ago