lambda式って何だろう
id:yagiey:20080204:1202147003の内容の続きっぽいけど...
// C#2.xにはFunc<T>が無い delegate TRet Func<TRet>(); // 匿名メソッドのテスト static void NotExpected() { // 手続きを作成 List<Func<int>> procs = new List<Func<int>>(); for (int i = 0; i < 5; i++) procs.Add(delegate() { return i; }); // 結果を出力 procs.ForEach(delegate(Func<int> f){ Console.WriteLine(f()); }); }
は、C#3以降だと
// lambda式のテスト static void AsExpected() { // 手続きを作成 List<Func<int>> procs = new List<Func<int>>( Enumerable.Range(0, 5).Select<int,Func<int>>(i => () => i)); // 結果を出力 procs.ForEach(f => Console.WriteLine(f())); }
ってすれば期待通り動いた。
でも、この期待って何?
なぜ、これが期待通りって僕は思ってるのかな。
たぶん...、Schemeのせい?