代表:predicate行动Func键 [英] Delegates: Predicate Action Func
问题描述
有人可以提供这3个最重要的代表一个很好的解释(希望与示例):
Can someone provide a good explanation (hopefully with examples) of these 3 most important delegates:
- predicate
- 动作
- 函数功能
还有什么其他代表们应C#开发人员知道的?
What other delegates should a C# developer be aware of?
你是否经常在生产中code使用它们?
How often do you use them in production code?
推荐答案
-
predicate
:基本上Func键< T,BOOL>
;问这个问题:不指定参数满足委托psented条件重新$ P $?使用之类的东西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.动作
:执行给定的参数动作。非常通用。不常用的LINQ,因为这意味着副作用,基本上是这样。Action
: Perform an action given the arguments. Very general purpose. Not used much in LINQ as it implies side-effects, basically.函数功能
:用于的广泛的LINQ中,通常改造的说法,例如通过投影复杂的结构来一个属性。Func
: Used extensively in LINQ, usually to transform the argument, e.g. by projecting a complex structure to one property.其他重要代表:
-
事件处理程序
/事件处理程序&LT; T&GT;
:用于全国各地的WinForms
EventHandler
/EventHandler<T>
: Used all over WinForms
比较&LT; T&GT;
:像的IComparer&LT; T&GT;
但在委托形式这篇关于代表:predicate行动Func键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
-