http://stackoverflow.com/questions/4317479/func-vs-action-vs-predicate

The difference between Func and Action is simply whether you want the delegate to return a value (use Func) or not (use Action).

Func is probably most commonly used in LINQ - for example in projections:

 list.Select(x => x.SomeProperty)

or filtering:

 list.Where(x => x.SomeValue == someOtherValue)

or key selection:

 list.Join(otherList, x => x.FirstKey, y => y.SecondKey, ...)

Action is more commonly used for things like List<T>.ForEach: execute the given action for each item in the list. I use this less often than Func, although I do sometimes use the parameterless version for things like Control.BeginInvoke and Dispatcher.BeginInvoke.

Predicate is just a special cased Func<T, bool> really, introduced before all of the Func and most of the Action delegates came along. I suspect that if we'd already had Func and Action in their various guises, Predicate wouldn't have been introduced... although it does impart a certain meaning to the use of the delegate, whereas Func and Action are used for widely disparate purposes.

Predicate is mostly used in List<T> for methods like FindAll and RemoveAll.

Func用于有返回值的方法,Action用于没有返回值的方法

Func<string>    表示一个有返回值的函数,返回值为string,但是函数没有参数

Func<stirng,string>  表示一个有返回值的函数,返回值为string,函数参数为string

Action<string>  表示一个无返回值的函数,函数参数为string

    Action b = Method;
private static void Method()
{
} Action<string> a = Method;
private static void Method(string str)
{
}
    Func<string> a = Method;
private static string Method()
{
return string.Empty;
} Func<string, string> b = Method;
private static string Method(string str)
{
return string.Empty;
}

最新文章

  1. 解析大型.NET ERP系统 灵活复杂的界面控件Infragistics WinForms
  2. Dom4jUtils.java
  3. AIX下禁止crs随ha启动而启动
  4. Git-克隆仓库
  5. 学习笔记——Maven超级POM
  6. Power Gating的设计(模块二)
  7. maven 添加支持编译jdk1.7
  8. java 最佳且开源的反编译工具
  9. android进程间通信:使用AIDL
  10. C#运用实例.读取csv里面的词条,对每一个词条抓取百度百科相关资料,然后存取到数据库
  11. 写移动端必备的meta标签
  12. 【Unity Shader实战】卡通风格的Shader(二)
  13. (转载)Python之道1-环境搭建与pycharm的配置django安装及MySQL数据库配置
  14. Mysql学习之基础
  15. UML和模式应用1: 面向对象的分析与设计
  16. 在Windows Server 2008的桌面上显示“我的电脑”“网上邻居”等图标?
  17. 51nod1462 树据结构(树链剖分+线段树)
  18. [LeetCode] 832. Flipping an Image_Easy
  19. 如何在单片机上使用printf函数(printf)(avr)(stm)(lpc)(单片机)(转)
  20. Jquery 操作 Select 详解

热门文章

  1. nutch如何修改regex-urlfilter.txt爬取符合条件的链接
  2. echarts 设置x轴的和y轴的属性
  3. ABAP FIELD-SYMBOLS 有大作用- 将没有可改參数的增强出口变得也能改主程序的值了
  4. leetcode第一刷_Add Binary
  5. TS 函数解析
  6. poj--2549--Sumsets(二分查找)
  7. web.xml配置详解(转载)
  8. Sql Server创建外键失败
  9. 【原创】RPM安装软件时解决依赖性问题(自动解决依赖型)
  10. SpringBoot学习笔记(16)----SpringBoot整合Swagger2