代表:谓语vs.动作vs.功能 [英] Delegates: Predicate vs. Action vs. Func

查看:103
本文介绍了代表:谓语vs.动作vs.功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以对这3个最重要的代表提供很好的解释(希望有例子)。

Can someone provide a good explanation (hopefully with examples) of these 3 most important delegates:


  • 谓词

  • 动作

  • 功能

推荐答案


  • 谓词:本质上是 Func< T,bool> ;提出问题指定的参数是否满足委托代表的条件?在类似List.FindAll的东西中使用。

    • Predicate: essentially Func<T, bool>; asks the question "does the specified argument satisfy the condition represented by the delegate?" Used in things like List.FindAll.

      Action :在给定参数的情况下执行操作。非常通用。

      Action: Perform an action given the arguments. Very general purpose. Not used much in LINQ as it implies side-effects, basically.

      Func :在LINQ中未使用太多,基本上就意味着副作用。在LINQ中>广泛地,通常用于转换参数,例如

      Func: Used extensively in LINQ, usually to transform the argument, e.g. by projecting a complex structure to one property.

      其他重要代表:


      • EventHandler / EventHandler< T> :全部使用在WinForms上

      • EventHandler/EventHandler<T>: Used all over WinForms

      Comparison< T> :就像 IComparer< T> ,但采用代理人形式。

      Comparison<T>: Like IComparer<T> but in delegate form.

      这篇关于代表:谓语vs.动作vs.功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆