private void PrintC() { MyActionA <int> a = (arg) => { Console.WriteLine("第一个:{0} ", arg); }; a += (arg) => { Console.WriteLine("第二个:{0} ", arg); }; a += (arg) => { Console.WriteLine("第三个:{0} ", arg); }; a += (arg) => { Console.WriteLine("第四个:{0} ", arg); }; a += PrintA; a(1); a.GetInvocationList(); }
private void PrintAct() { MyActionA <int> a = PrintA; MyActionA <int> b = pa => Console.WriteLine("{0}", pa); //匿名委托 MyActionA <string> c = delegate(string aa) { Console.WriteLine("{0}", aa); }; a(1); b(2); c("anonymous Act"); MyActionA <int> d = PrintA; d += delegate(int pb) { Console.WriteLine("anonymous 2:{0}", pb); }; d(2); }