. NET enumeration we generally have two usages, one is to represent the unique sequence of elements, and the other is to represent a variety of composite states. This time it is generally necessary to mark the enumeration with the [Flags] attribute as a bit field, so that we can use the "or" operator to combine multiple states.
For example:
[Flags]
public enum Permission
{
Create = 1,
Read = 2,
Update = 4,
Delete = 8,
}
Permission Permission = Permission.create | Permission.read | Permission.update | Permission.delete;
Console.WriteLine ("1, enum creation, and Assignment ...");
Console.WriteLine (permission. ToString ());
Console.WriteLine ((int) permission);
Permission = (permission) enum.parse (typeof (Permission), "5");
Console.WriteLine ("2, convert by numeric string ...");
Console.WriteLine (permission. ToString ());
Console.WriteLine ((int) permission);
Permission = (permission) enum.parse (typeof (Permission), "Update, delete, read", true);
Console.WriteLine ("3, converting by enumeration name string ...");
Console.WriteLine (permission. ToString ());
Console.WriteLine ((int) permission);
Permission = (permission) 7;
Console.WriteLine ("4, direct with digital coercion ...");
Console.WriteLine (permission. ToString ());
Console.WriteLine ((int) permission);
Permission = permission & ~permission.read;
Console.WriteLine ("5, remove an enumeration item ...");
Console.WriteLine (permission. ToString ());
Console.WriteLine ((int) permission);
Permission = permission| Permission.delete;
Console.WriteLine ("6, plus an enumeration ...");
Console.WriteLine (permission. ToString ());
Console.WriteLine ((int) permission);
In the database, Judge:
and (@permission is NULL or @permission =0 or permission & @permission [email protected])
Reference: http://www.cnblogs.com/youring2/archive/2011/12/16/2289832.html
The flags attribute is used in C # enumerations