when decorated with the Flags attribute, you can do what you are doing and it's perfectly fine.. The CLR is telling you that the value assigned to the enum instance is and Administrator Or a Manager... thats what the vertical pipe is, a bitwise Or operator.
From the msdn page msdn Flags Attribute
"Consider creating an enumerated
constant for commonly used flag
combinations. For example, if you have
an enumeration used for file I/O
operations that contains the
enumerated constants Read = 1 and
Write = 2, consider creating the
enumerated constant ReadWrite = Read
OR Write, which combines the Read and
Write flags. In addition, the bitwise
OR operation used to combine the flags
might be considered an advanced
concept in some circumstances that
should not be required for simple
tasks."
You could have just as easily have declared the enum as follows:
[Flags]public enum PermissionLevel
{
User = 1,
Administrator = 2,
ITStaff = User | Administrator,
Manager = 4,
SuperAdministrator = Administrator | Manager ,
}
and oh, btw, it's considered good practice to always include a None value...
[Flags]public enum PermissionLevel
{
None = 0,
User = 1,
Administrator = 2,
ITStaff = User | Administrator,
Manager = 4,
SuperAdministrator = Administrator | Manager ,
}
This technique is extremely useful, as it allows client code to test a candidate value against a subset of the individual values using syntax that concisely expresses the actual business intent... assuming candValue is one of core individual values...
if ((candValue & PermissionLevel.SuperAdministrator) == candVal)
// tests to see if candValue is Administrator Or Manager
which would require 2 comparisons if you did not have access to an enum value that represented the SuperAdministrator bitmask = 00000110