Tuesday, August 17, 2010

C# Delegates

Nice post on Action, Predicate, and Func delegates: Cool Delegates

Quick Reference:
/*
* Action -    
*    o accepts zero or up to four parameters and returns void
*    o Action                         :: public delegate void DelegateName()
*    o Action<T>                      :: public delegate void DelegateName(T)
*    o Action<T1, T2>                 :: public delegate void DelegateName(T1, T2)
*    o Action<T1, T2, T3>             :: public delegate void DelegateName(T1, T2, T3)
*    o Action<T1, T2, T3, T4>         :: public delegate void DelegateName(T1, T2, T3, T4)
* 
* Predicate - 
*    o accepts a single parameter and returns a bool  
*    o Predicate<T>                   :: public delegate bool DelegateName(T)
*     
* Func -
*    o acepts zero or up to four parameters and returns any type (TResult)
*    o Func<TResult>                  :: public delegate <TResult> DelegateName()
*    o Func<T, TResult>               :: public delegate <TResult> DelegateName(T1)
*    o Func<T1, T2, TResult>          :: public delegate <TResult> DelegateName(T1, T2)
*    o Func<T1, T2, T3, TResult>      :: public delegate <TResult> DelegateName(T1, T2, T3)
*    o Func<T1, T2, T3, T4, TResult>  :: public delegate <TResult> DelegateName(T1, T2, T3, T4)
* 
*/

No comments: