Coffeehouse Post

Single Post Permalink

View Thread: C# Extension Properties?
  • User profile image

    mabster wrote:
    Yeah, I was hoping for extension properties too:

    public static TimeSpan Minutes[this int i]
       getreturn new TimeSpan(0, i, 0); }

    public static DateTime Ago[this TimeSpan ts]
       get { return DateTime.Now.Subtract(ts); }

    So then I could do:

    DateTime d = 20.Minutes.Ago;

    No ugly parentheses!

    Sweet. That looks Ruby'ish (not to be mistaken by Rubish). Not that I like Ruby. Smiley