C# .NET: if ((e.State & ListViewItemStates.Selected) != 0) <- What does it mean?
.net, bit-manipulation, c#, listview
Solution
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).
Problem
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 ..