有了这个匿名委托就会了(匿名委托的各种写法)
1 //匿名代理 2 Action a = delegate() { Console.WriteLine("输出"); Thread.Sleep(1000); }; 3 a(); 4 5 //匿名lambda 6 Action b = () => { Console.WriteLine("输出"); }; 7 8 b(); 9 10 //有参数无返回值 11 Action<string> c = delegate(string k) { Console.WriteLine(k); Thread.Sleep(1000); }; 12 13 Action<string> d = p => { Console.WriteLine(p); Thread.Sleep(1000); }; 14 15 d("ss"); 16 17 //无参数 有返回值 18 Func<string> f = delegate() { return "hello"; }; 19 20 Func<string> g = () => { return "hello"; }; 21 f();
1 //有参有返 2 Func<string, string> h = p => { return p + "help"; }; 3 4 Func<string, string> j = p => { return p + "you win"; };
淘宝搜索 彤彤丽舍 收藏下店铺就是对我最大的鼓励。
有了这几个匿名写法就会了