I have a flag enum below.
[Flags]
public enum FlagTest
{
None = 0x0,
Flag1 = 0x1,
Flag2 = 0x2,
Flag3 = 0x4
}
I cannot make the if statement evaluate to true.
FlagTest testItem = FlagTest.Flag1 | FlagTest.Flag2;
if (testItem == FlagTest.Flag1)
{
// Do something,
// however This is never true.
}
How can I make this true?
None
flag with a value of zero. See msdn.microsoft.com/en-us/library/vstudio/… – Graham&
operator for comparison,|
is like an addition:1|2=3
,5|2=7
,3&2=2
,7&2=2
,8&2=0
.0
evaluates tofalse
, everything else totrue
. – Calathus