6 Important Delegates

  1. 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.
  2. Action: Perform an action given the arguments. Very general purpose. Not used much in LINQ as it implies side-effects, basically.
  3. Func: Used extensively in LINQ, usually to transform the argument, e.g. by projecting a complex structure to one property.
  4. EventHandler/EventHandler<T>: Used all over WinForms
  5. Comparison<T>: Like IComparer<T> but in delegate form.
  6. Converter<TInput, TOutput>: It’s essentially Func<TInput, TOutput>, but with semantics. Used by List.ConvertAll and Array.ConvertAll, but personally haven’t seen it anywhere else.The Converter is a nice delegate when a lot of Converting of Model into Business classes is needed, i.e. http://www.stum.de/2009/12/23/using-a-converter-to-convert-from-a-model-to-a-business-class/

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>