class Program { public static void zhixing(string str) { Console.WriteLine(str); }//一个方法 public delegate void xxxx(string s); //代理是以方法为参数的类 static void Main(string[] args) { xxxx x = new xxxx(zhixing); //实例化代理 xxxx x1 = new xxxx(delegate (string s) { Console.WriteLine(s); }); //匿名方法 xxxx x2 = new xxxx((string s)=> { Console.WriteLine(s); }); //简写:去掉delegate xxxx x3 = new xxxx((string s) => Console.WriteLine(s)); //简写:去掉大括号 xxxx x4 = new xxxx((s) => Console.WriteLine(s)); //简写去掉参数类型 xxxx x5 = (s) => Console.WriteLine(s); //简写 去掉new xxx() } }
public deleget void xxxx(string str); 代理是以方法为参数的类
xxxx x=new xxxx(zhixing); 代理的实例化 简写:匿名方法 xxxx x=new xxxx(deleget(string s){console.write(s);})
lambda xxxx x=new xxxx(()=>{console.write("aaaaaaaaaaaa");})
xxxx x=new xxxx(()=>console.write("aaaaaaaaaaaa"));
xxxx x=()=>console.write("aaaaaaaaaaaa");
x.invoke(); 代理执行
public void zhixing(string s)
{console.write(s);
}