====== 実行結果 ====== Result(ラムダ式): 25 Result(匿名メソッド): 25 ====== ソース ====== using System; namespace console { class Program { public delegate int SquareDelegate(int arg); static void Main(string[] args) { // ラムダ式の例(C#3.0で導入) // Func<引数の型, 戻り値の型> square = 引数の変数名 => 処理; // ラムダ式の実行は square(5) のように行う。 Func square = arg => arg * arg; Console.WriteLine("Result(ラムダ式): {0}", square(5)); // 匿名メソッド(C#2.0で導入) // メソッドを型として本クラスの冒頭で定義している。 // 以下で匿名メソッドの処理を定義している。 // 匿名メソッドの型 square2 = delegate(int arg){ ... } // 匿名メソッドの実行は square2(5) のように行う。 SquareDelegate square2 = delegate(int arg) { return arg * arg; }; Console.WriteLine("Result(匿名メソッド): {0}", square2(5)); } } }