委托 - Action 和 Func

复制代码
        Action<int> al = delegate (int i) { Console.WriteLine(i); };
            al(3);
            //lambda表达式格式的匿名方法的写法
            Action<int> a2 = (int i) => { Console.WriteLine(i); };
            a2(666);
            Action<int> a3 = (i) => { console.WriteLine(i); }
            a3(888);
            //如果有一个参数,可以不写参数的小括号
            Action<int> a4 = i => { Console.WriteLine(i); }; 
            a4(999);
            Func<string, int, bool> f1 = delegate (string s, int i) { return true; };
            Func<string, int, bool> f2 = (string s, int i) => { return true; }; 
            Func<string, int, bool> f3 = (s, i) => { return true; };
            Func < stringintbool> f4 = (s, i) => true; //如果方法有返回值,并且只有一行,那么就可以连方法的大括号和return都省略
复制代码

 

 
posted @   Tammytan  阅读(36)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示