tabs ↹ over ␣ ␣ ␣ spaces

by Jiří {x2} Činčura

Enum.HasFlag is in .NET 4

22 Oct 2009 1 mins .NET

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.

Profile Picture Jiří Činčura is .NET, C# and Firebird expert. He focuses on data and business layers, language constructs, parallelism, databases and performance. For almost two decades he contributes to open-source, i.e. FirebirdClient. He works as a senior software engineer for Microsoft. Frequent speaker and blogger at www.tabsoverspaces.com.