title: C# Enums - Check Flags against a Mask
body: <p>I have the following enum flags:</p>
  
  <pre><code>[Flags]
  private enum MemoryProtection: uint
  {
      None             = 0x000,
      NoAccess         = 0x001,
      ReadOnly         = 0x002,
      ReadWrite        = 0x004,
      WriteCopy        = 0x008,
      Execute          = 0x010,
      ExecuteRead      = 0x020,
      ExecuteReadWrite = 0x040,
      ExecuteWriteCopy = 0x080,
      Guard            = 0x100,
      NoCache          = 0x200,
      WriteCombine     = 0x400,
      Readable         = (ReadOnly | ReadWrite | ExecuteRead | ExecuteReadWrite),
      Writable         = (ReadWrite | WriteCopy | ExecuteReadWrite | ExecuteWriteCopy)
  }
  </code></pre>
  
  <p>Now i have an enum instance that I need to check if it's readable. If I use the following code:</p>
  
  <pre><code>myMemoryProtection.HasFlag(MemoryProtection.Readable)
  </code></pre>
  
  <p>It always returns false in my case because I think HasFlag check if it has every flag. I need something elegant to avoid doing this:</p>
  
  <pre><code>myMemoryProtection.HasFlag(MemoryProtection.ReadOnly)         ||
  myMemoryProtection.HasFlag(MemoryProtection.ReadWrite)        ||
  myMemoryProtection.HasFlag(MemoryProtection.ExecuteRead)      ||
  myMemoryProtection.HasFlag(MemoryProtection.ExecuteReadWrite)
  </code></pre>
  
  <p>How can I do it?</p>