First here are two extension methods. The first one, Hours, extends int type; and the second one, FromNow, extends TimeSpan type.
public static TimeSpan Hours(this int i) { return new TimeSpan(0, i, 0, 0); } public static DateTime FromNow(this TimeSpan t) { return DateTime.Now.Add(t); } |
So I can write something like this:
DateTime ThreeHoursFromNow = 3.Hours().FromNow(); |
Probably my example cannot illustrate the power of extension methods, but well, you get the idea. :)
No comments:
Post a Comment