graphics.hatenablog.com

技術系テクニカルアーティストのあれこれ

LINQを理解するためのC#についての補足。

前の記事の補足。

graphics.hatenablog.com

ラムダ式

たとえばこのコードは

Func<int, string> itoa = (integer) => integer.ToString();
Console.WriteLine(itoa(1));

こんなかんじに展開される。(実際にはちょっとちがう)

class functor {
    static internal string itoa(int integer) {
        return integer.ToString();
    }
}

Func<int, string> iota = functor.itoa;
Console.WriteLine(itoa(1));

拡張メソッド

たとえばこのコードは

static class extentions {
    public static string itoa(this int integer) {
        return integer.ToString();
    }
}

Console.WriteLine(1.itoa());

こんなかんじに展開される。

Console.WriteLine(extentions.itoa(1));