Enum.HasFlag is in .NET 4
Today I noticed, that in beta 2 of .NET Framework 4 (and Visual Studio 2010) there’s a new method for enums – HasFlag. Using bitwise operators was sometimes ugly and decreased the readability of code, hence (I think) almost everybody wrote similar method i.e.:
static bool HasFlag(this Enum e, Enum flag)
{
return ((Convert.ToInt32(e) & Convert.ToInt32(flag)) != 0);
}
But now it’s directly in framework. Great! I like these small additions that make life easier.