Comment

Comment by mattmanser

Extension methods in C# do the same thing and have been around, what 5ish years now? Since .Net 3.5.

Here's an example implementation:

    public static class DateExtension
    {
        public static TimeSpan Days(this int daysCount)
        {
            return new TimeSpan(daysCount, 0, 0, 0); //days, hours, mins, secs for those wondering
        }

        public static DateTime FromNow(this TimeSpan addTime) 
        {
            return DateTime.Now.Add(addTime);
        }
    }
usage is the same as Rust:

    2.Days().FromNow();
Basically if this impresses you, you really should give modern C# a whirl as there's a lot more you can do than that.

Much of how it does stuff now is how my perfect language would do it. There are bits of Ruby I love, and Rust is looking more exciting to me than Go, but the C# team really have done some amazing work.

parent mattmanser 13 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton