Friday, September 16, 2011

leave off the namespace when writing extension methods!

The real magic for extension methods lies in leaving off the namespace designation!

using System;

public static class DateTimeExtensions

{

   public static string ToYearString(this DateTime dateTime)

   {

      return dateTime.Year.ToString();

   }

}

No comments:

Post a Comment