In standard MSN code, there's a line on a ListView - Ownerdraw - DrawItem :
if ((e.State & ListViewItemStates.Selected) != 0)
{
//Draw the selected background
}
Apparently it does a bitwise comparison for the state ?? Why bitwise ? The following doesn't work:
if (e.State == ListViewItemStates.Selected)
{
//Doesn't work ??
}
Why doesn't that comparison work ? It's just a standard Enum ?? I'm a bit bedaffled ..
It's not a standard Enum - it's decorated with the FlagsAttribute
, making it a bitmask. See MSDN FlagsAttribute for details.
The first example checks whether any of the flags is set, as you have rightly interpreted. Flags are generally combined using the | operator (though + and ^ are also safe for a properly specified attribute with no overlaps).
It's possible to use Enumeration Types as Bit Flags.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With