static void DelegateMethod01() { // メソッドをデリゲートに代入 sumDelegate sumDele = Sum; // 引数を入れて、Sumメソッドを使う sumDele(1, 2); }
static void Main(string[ ] args) { int a = 1, b = 2, c; sumDelegate sd = delegate( int aa, int bb) { return aa + bb; } ; c = sd(a, b); Console.WriteLine("{0} + {1} = {2}",a, b, c); }
static void Main(string[] args) { int a = 1, b = 2, c; c = sum(a, b); Console.WriteLine("{0} + {1} = {2}", a, b, c); sumDelegate mySumDelegate; mySumDelegate = new sumDelegate(sum); c = mySumDelegate(a, b); Console.WriteLine("{0} + {1} = {2}", a, b, c); }