委托三- - - - - - - - - - - -多播委托与匿名方法

  

============================================多播委托

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -主程序

using 系统;   using  System.Collections.Generic;   using 来;   using 包含;   using  System.Threading.Tasks;   namespace  ConsoleApplication3   {   ,,,class 程序   ,,,{   ,,,,,,,static  void  Main (string [], args)   ,,,,,,,{   ,,,,,,,,,,,//多播委托只能使用无返回值的委托   ,,,,,,,,,,,//当str1执行失败后会阻止后面的方法的执行   ,,,,,,,,,,,Action, a =, str1;   ,,,,,,,,,,,a  +=, str2;   ,,,,,,,,,,,a  +=, str2;   ,,,,,,,,,,,a  +=, str2;   ,,,,,,,,,,,a  +=, str2;   ,,,,,,,,,,,StrAndName (a,“文聘”);   ,,,,,,,,,,,Console.ReadKey ();   ,,,,,,,}      ,,,,,,,static  void  str1 (string 名称)   ,,,,,,,{   ,,,,,,,,,,,Console.WriteLine(“看我{0}的厉害”,,名字);   ,,,,,,,}   ,,,,,,,static  void  str2 (string 名称)   ,,,,,,,{   ,,,,,,,,,,,Console.WriteLine(“受死吧!”{0},,名字);   ,,,,,,,}   ,,,,,,,static  void  StrAndName (Action

,

============================================匿名方法

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -主程序

using 系统;   using  System.Collections.Generic;   using 来;   using 包含;   using  System.Threading.Tasks;   namespace  ConsoleApplication4   {   ,,,class 程序   ,,,{   ,,,,,,,static  void  Main (string [], args)   ,,,,,,,{   ,,,,,,,,,,,string  s =,“你好!”;   ,,,,,,,,,,,//不能使用,goto,继续,裁判,   ,,,,,,,,,,,Action, a =,委托(string  str)   ,,,,,,,,,,,{   ,,,,,,,,,,,,,,,Console.WriteLine(时间+ s  str);   ,,,,,,,,,,,,,,,Console.ReadKey ();   ,,,,,,,,,,,};   ,,,,,,,,,,,一个(“我叫张飞”);      ,,,,,,,}   ,,,}   }

委托三- - - - - - - - - - - -多播委托与匿名方法