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;
}

Func委托和Action委托的更多相关文章

  1. C#中常见的委托(Func委托、Action委托、Predicate委托)

    今天我要说的是C#中的三种委托方式:Func委托,Action委托,Predicate委托以及这三种委托的常见使用场景. Func,Action,Predicate全面解析 首先来说明Func委托,通 ...

  2. Func 委托 和 Action 委托 初步谈论

    继上篇EventHandler之后,继续填坑,简单了解下Func<TResult> 委托 和 Action 委托. msdn对于两者的解释: Func<TResult>:封装一 ...

  3. [C#学习笔记]Func委托与Action委托

    学习一项新知识的时候,最好的方法就是去实践它. 前言 <CLR via C#>这本神书真的是太有意思了!好的我的前言就是这个. Fun 如果要用有输入参数,有返回值的委托,那么Func委托 ...

  4. C#内置泛型委托:Action委托

    1.什么是Action泛型委托 Action<T>是.NET Framework内置的泛型委托,可以使用Action<T>委托以参数形式传递方法,而不用显示声明自定义的委托.封 ...

  5. .NET : Func委托和Action委托

    其实他们两个都是委托[代理]的简写形式. 一.[action<>]指定那些只有输入参数,没有返回值的委托 Delegate的代码: public delegate void myDeleg ...

  6. 委托delegate 泛型委托action<> 返回值泛型委托Func<> 匿名方法 lambda表达式 的理解

    1.使用简单委托 namespace 简单委托 { class Program { //委托方法签名 delegate void MyBookDel(int a); //定义委托 static MyB ...

  7. C#系统委托之Action And Func

    Action Action<T> Func Func<T> Action:封装一个方法,该方法不具有参数并且不返回值 public delegate void Action() ...

  8. Func<T>与Action<T>委托泛型介绍:转

    .Net 3.5之后,微软推出了Func<T>与Action<T>泛型委托.进一步简化了委托的定义. Action<T>委托主要的表现形式如下: public de ...

  9. Func<T>与Action<T>委托泛型介绍

    .Net 3.5之后,微软推出了Func<T>与Action<T>泛型委托.进一步简化了委托的定义. Action<T>委托主要的表现形式如下: public de ...

随机推荐

  1. NYIST 749 蚂蚁的难题(八)

    蚂蚁的难题(八)时间限制:2000 ms | 内存限制:65535 KB难度:5 描述蚂蚁是一个古玩爱好者,他收藏了很多瓶瓶罐罐. 有一天,他要将他的宝贝们一字排开, 摆放到一个长度为L的展台上. 已 ...

  2. Floodlight 中创建消息对象的方法

            在 floodlight 中创建各种openflow message 和 action 等採用的是简单工厂方式.BasicFactory类(实现OFMessageFactory接口.) ...

  3. oracle 11g sql developer安装后无法使用

    oracle11g安装后出现   再去官网单独下来个sql developer安装 sql developer须要jre支持

  4. 【从零之六&amp;完结】android口语对话系统(RavenClaw java版 含所有源代码)

    ! !! 更新:最新源码放到了github上,认为还不错点个星啊! 点击打开链接 做了一个半月最终完毕了,以下这个就是我參考Olympus/RavenClaw系统编写的对话管理系统.眼下实现了一个简单 ...

  5. HTTP Status 404 - /servlet/Item/AddItemServlet

    我想学习编程的人对404和500都是非常敏感非常熟悉的.在做DRP系统的时候多次遇到这两个错误,今天让我遇到他并且让我铭记他,那就是一个"/": 这是说jsp出问题了,并且找不到, ...

  6. sqlite学习笔记9:C语言中使用sqlite之插入数据

    前面创建了一张表,如今给他插入一些数据.插入数据跟创建表差点儿相同,不过SQL语言不一样而已,完整代码例如以下: #include <stdio.h> #include <stdli ...

  7. node09---中间件

    如果我的的get.post回调函数中,没有next参数,那么就匹配上第一个路由,就不会往下匹配了. 如果想往下匹配的话,那么需要写next() 1app.get("/",funct ...

  8. bzoj2464: 中山市选[2009]小明的游戏(最短路)

    2464: 中山市选[2009]小明的游戏 题目:传送门 题解: 最短路的裸题... 代码: #include<cstdio> #include<cstring> #inclu ...

  9. bzoj3436: 小K的农场(差分约束)

    3436: 小K的农场 题目:传送门 题解: 查分基础: t==1  a>=b+c t==2  b>=a-c t==3  a>=b+0 b>=a+0 跑最长路一A 代码: #i ...

  10. Transformation in kentico

    https://docs.kentico.com/k10/developing-websites/loading-and-displaying-data-on-websites/writing-tra ...