/// <summary> /// デリゲート通常使用メソッド /// </summary> static void ExecDelegate() { //デリゲート対象メソッド01をデリゲートに代入 deleTestA del01 = new deleTestA(test01); //デリーゲート使用 del01(100, 101); }
/// <summary> /// デリゲートラムダ式使用メソッド /// </summary> static void ExecLamda() { //ラムダ式をデリゲートに代入 //返り値ありで引数を複数取るラムダ式 deleTestA del02 = (x, y) => x * 1; //デリーゲート使用 int j = del02(200, 201); Console.WriteLine("デリゲートラムダ式使用1:" + j.ToString()); //返り値ありで引数を複数取るラムダ式 deleTestA del03 = (x, y) => { x = x * 1; return(x); }; //デリーゲート使用 int k = del03(300, 301); Console.WriteLine("デリゲートラムダ式使用2:" + k.ToString()); //返り値なしで引数を一つ取るラムダ式 deleTestB del04 = x => Console.WriteLine("デリゲートラムダ式使用3:" + x.ToString()); //デリーゲート使用 del04(400); //返り値なしで引数を一つ取るラムダ式 deleTestB del05 = x => { x = x * 1; Console.WriteLine("デリゲートラムダ式使用4:" + x.ToString()); }; //デリーゲート使用 del05(500); //返り値なしで引数を取らないラムダ式 deleTestC del06 = () => Console.WriteLine("デリゲートラムダ式使用5:引数なし"); //デリーゲート使用 del06(); }