C# Extension Methods - How far is too far?
问题 Rails introduced some core extensions to Ruby like 3.days.from_now which returns, as you'd expect a date three days in the future. With extension methods in C# we can now do something similar: static class Extensions { public static TimeSpan Days(this int i) { return new TimeSpan(i, 0, 0, 0, 0); } public static DateTime FromNow(this TimeSpan ts) { return DateTime.Now.Add(ts); } } class Program { static void Main(string[] args) { Console.WriteLine( 3.Days().FromNow() ); } } Or how about: