C# Enum.HasFlag vs. Bitwise AND Operator Check
<p>If you have an <code>enum</code> that is used for bit flags, i.e.,</p>

<pre><code>[Flags]
internal enum _flagsEnum : byte
{
    None = 0,           //00000000
    Option1 = 1,        //00000001
    Option2 = 1 &lt;&lt; 1,   //00000010
    Option3 = 1 &lt;&lt; 2,   //00000100
    Option4 = 1 &lt;&lt; 3,   //00001000
    Option5 = 1 &lt;&lt; 4,   //00010000
    Option6 = 1 &lt;&lt; 5,   //00100000
    Option7 = 1 &lt;&lt; 6,   //01000000
    Option8 = 1 &lt;&lt; 7,   //10000000
    All = Byte.MaxValue,//11111111
}

_flagsEnum myFlagsEnum = _flagsEnum.None;
</code></pre>

<p>Is it faster to do..</p>

<pre><code>bool hasFlag = myFlagsEnum.HasFlag(_flagsEnum.Option1);
</code></pre>

<p>or to do..</p>

<pre><code>bool hasFlag = myFlagsEnum &amp; _flagsEnum.Option1 != 0
</code></pre>

<p>If there's a performance difference between checking multiple flags, then take that into account as well.</p>

<p>Normally I'd check out the reference source, but in this case Enum.HasFlags just goes to an extern InternalHasFlags, so I have no idea what it's doing.</p>