Code Analysis With Captured Variables

I am a big fan of using Code Analysis (formerly FXCop) in my Visual Studio projects to help catch issues. Recently I ran across a CA2208 warning that I needed to think about. Usually these are simple results of refactoring or forgetting to include the argument name in the ArgumentNullException or ArgumentOutOfRangeException. This one, however, was a little different. The… Read more »

Getting the Name of the Day of the Week in C#

Getting the current day of week in C# is pretty easy, if all you need is the english version of the day, for example: MessageBox.Show(System.DateTime.Now.DayOfWeek.ToString()); But if you want to get the Day of Week for the current language the computer is setup for, the above code will not work. You need to access the Globalization class and get the… Read more »

Why Does This Implicit Conversion Fail?

There was a recent question on StackOverflow that piqued my interest and was a rather interesting problem dealing with some odd behavior someone observed with implicit operators. Consider the following wrapper class: sealed class Wrapper<T> : IDisposable { public T Child { get; private set; } public Wrapper(T child) { Child = child; } public static implicit operator Wrapper<T>(T child)… Read more »