Enum.HasFlag

In not-so-new news, I just found out about .NET 4’s Enum.HasFlag method. This nice little method makes life with flags a little bit cleaner since you can use it instead of performing a bitwise AND and compare.

[Flags]
enum Options
{
	None = 0,
	A = 1,
	B = 2,
	C = 4
}

void Main()
{
	var options = Options.A | Options.C;
	
	// old (bitwise AND and compare)
	Console.WriteLine("A:{0}", (options & Options.A) == Options.A);
	Console.WriteLine("B:{0}", (options & Options.B) == Options.B);
	Console.WriteLine("C:{0}", (options & Options.C) == Options.C);
	
	// new (HasFlag method)
	Console.WriteLine("A:{0}", options.HasFlag(Options.A));
	Console.WriteLine("B:{0}", options.HasFlag(Options.B));
	Console.WriteLine("C:{0}", options.HasFlag(Options.C));
}

/* Output:
A:True
B:False
C:True
A:True
B:False
C:True
 */

Blurry Monitors in Windows 8.1

As mentioned in yesterday’s post, I’ve been rocking a new Lenovo T440S. I noticed that whenever I attached an extra monitor, the display would get blurry. Some quick internet research suggests that this may be related to Windows 8.1 auto-scaling that attempts to make things on different screens appear to be the same size. Luckily, Microsoft has published a support article that offers two solutions to this problem: disabling DPI virtualization for specific applications or lowering the Windows DPI setting.

Both solutions worked for me, but I opted for #2 since I’m not particularly interested in dealing with the problem on a per-application basis.

Here’s the short version of how to do that:

  1. Go to Control Panel > Appearance and Personalization > Display
  2. Check Let me choose one scaling level for all my displays
  3. Optional – Choose the scaling percentage to use (I use Smaller – 100%)
  4. Click Apply