Enum.HasFlag – where have you been all my life?

Tuesday, August 24, 2010

If youโ€™ve ever used enumerations in .NET with bitwise operations, using the Flags attribute, you should be familiar with the following piece of code: enum Permission{  None = 0,  Read = 1,  Edit = 2,  Delete = 4,  ChangePermission = 8,  FullControl = Read | Edit | Delete | ChangePermission} Permission permission = Permission.Read | Permission.Edit; if ((permission & Permission.Delete) == Permission.Delete)  Console.WriteLine("Has permissions"); In .NET 4, a new method was introduced in order to relieve yourself from this ugly...
one comment