Delegates: Predicate vs. Action vs. Func(代表:谓词 vs. 动作 vs. Func)
问题描述
有人可以对这 3 位最重要的代表提供一个很好的解释(希望有例子):
Can someone provide a good explanation (hopefully with examples) of these 3 most important delegates:
- 谓词
- 行动
- 功能
推荐答案
谓词
:本质上是Func
;提出问题指定的参数是否满足委托所代表的条件?"用于 List.FindAll 之类的东西.Predicate
: essentiallyFunc<T, bool>
; asks the question "does the specified argument satisfy the condition represented by the delegate?" Used in things like List.FindAll.Action
:给定参数执行一个动作.非常通用的用途.在 LINQ 中使用不多,因为它基本上意味着副作用.Action
: Perform an action given the arguments. Very general purpose. Not used much in LINQ as it implies side-effects, basically.Func
:在 LINQ 中广泛使用,通常用于转换参数,例如通过将复杂结构投影到一个属性.Func
: Used extensively in LINQ, usually to transform the argument, e.g. by projecting a complex structure to one property.其他重要代表:
EventHandler
/EventHandler
:在整个 WinForms 中使用
EventHandler
/EventHandler<T>
: Used all over WinForms
Comparison<T>
:与IComparer
类似,但采用委托形式. Comparison<T>
: LikeIComparer<T>
but in delegate form.这篇关于代表:谓词 vs. 动作 vs. Func的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:代表:谓词 vs. 动作 vs. Func


- WebMatrix WebSecurity PasswordSalt 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 输入按键事件处理程序 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01