Action<>和Func<> 区别
2024-09-22 06:24:35
其实他们两个都是委托【代理】的简写形式。
一、【action<>】指定那些只有输入参数,没有返回值的委托
Delegate的代码:
- public delegate void myDelegate(string str);
- public static void HellowChinese(string strChinese)
- {
- Console.WriteLine("Good morning," + strChinese);
- Console.ReadLine();
- }
- myDelegate d = new myDelegate(HellowChinese);
- d("Mr wang");
用了Action之后呢:
- public static void HellowChinese(string strChinese)
- {
- Console.WriteLine("Good morning," + strChinese);
- Console.ReadLine();
- }
- Action<string> action = HellowChinese;
- action("Spring.");
就是相当于省去了定义委托的步骤了。
二、func<> 这个和上面的那个是一样的,区别是这个有返回值!
- public static string HelloEnglish(string strEnglish)
- {
- return "Hello." + strEnglish;
最新文章
- MongoDB系列一:CentOS7.2下安装mongoDB3.2.8
- fetch 资源请求
- install docker on xubuntu
- C# TreeView的CheckBox 父/子节点点击联动选择效果
- IE8/9的console之坑
- JAVA基础知识之多线程——线程同步
- fushioncharts的使用教程
- ctags 文章
- python内建函数sorted方法概述
- httpClient模拟浏览器发请求
- Java项目中基于Hibernate分页总结
- uva-10487 - Closest Sums
- 《转载》CSS中的三种样式来源:创作人员、读者和用户代理
- 【动态规划】【归并】Vijos P1412 多人背包
- Scala学习笔记--xml
- 重写ViewPager实施单一交有关切换到这个问题,并没有缓存
- Appium键盘操作
- A标签中通过href和onclick传递的this对象
- Python教程(2.1)——控制台输入
- ConcurrentHashMap基于JDK1.8源码剖析