Hi Jacek, Interesting, I thought I had been using 'HasFlag on the MouseButtons Enum in Windows Forms previous to .NET 4.0. Also interesting about 'HasFlag is that it will work even on Enumerations that are not decorated with the [Flags] Attribute, while the MS documentation implies, in my reading, that it only works with same: "The HasFlag method is designed to be used with enumeration types that are marked with the FlagsAttribute attribute."
// from the MS doc for Enum.HasFlag
// no \[Flags\] attribute !
public enum DinnerItems
{
None = 0,
Entree = 1,
Appetizer = 2,
Side = 4,
Dessert = 8,
Beverage = 16,
BarBeverage = 32
}
// execute this somewhere in your code
DinnerItems thisMeal;
// This will also compile without error in .NET 4.0 !
// DinnerItems thisMeal = new DinnerItems();
thisMeal = DinnerItems.Dessert;
if (thisMeal == DinnerItems.Dessert) MessageBox.Show("woof woof");
if(thisMeal.HasFlag(DinnerItems.Dessert)) MessageBox.Show("meow");
The comment on the MSDN page you linked to by a "community member" that using 'HasFlag is "1000 times slower" than the "standard method" is kind of scary. best, Bill
"Reason is the natural order of truth; but imagination is the organ of meaning." C.S. Lewis