Today I passed the second certification exam 70-502. So now I’m officially a Microsoft Certified Technology Specialist: .NET Framework 3.5, Windows Presentation Foundation Applications.
Monday, February 01, 2010
If you ever tried to format a nullable type you would soon realize that you cannot directly as Nullable<T> does not implement IFormattable and thus you only have object.ToString() available.
This is easily fixed using an extension method:
public static class NullableExtensions
public static string ToString<T>(
this Nullable<T> nullable,
where T : struct, IFormattable
if (!nullable.HasValue) return string.Empty;
T notNull = nullable.Value;
return notNull.ToString(format, formatProvider);
DateTime? foo = null;