3 ms·
Funny thing, that construction is actually pretty easy to achieve in buttoned-up and statically typed C# with extension methods: static TimeSpan Weeks(
by kryptiskt 5y ago
Funny thing, that construction is actually pretty easy to achieve in buttoned-up and statically typed C# with extension methods:
static TimeSpan Weeks(this System.Int32 n)
{
return new TimeSpan(n*7, 0, 0, 0);
}
static DateTime FromNow(this TimeSpan dt)
{
return DateTime.Now.Add(dt);
}
static void Main(string[] args)
{
Console.WriteLine(2.Weeks().FromNow());
}
- deleted 5y ago[deleted]
- joelbluminator 5y agoI'm impressed actually.
- eloisius 5y agoNot bad! I also feel like it’s worth mentioning that in rust you can extend primitive types with traits. I’ve done that to add some bit-munging helpers while working on a toy Game Boy emulator to make it easier to deal with 16- and 8-bit register values like (8, 8).join() and (l, h) = 16.split().