Action, Func and Predicate

Action, Func and Predicate are in-built delegates in .NET.

Action delegate

It comes in two variants, generic and non-generic.

Assembly: mscorlib (mscorlib.dll)
Namespace: System

Action_Delegate_Old

The Non-Generic version encapsulates a method that has no parameters and does not return a value.

 public delegate void Action()

The Generic version encapsulates a method that has one or more input parameters and does not return a value. It takes up to 8 input parameters.

public delegate void Action<in T>(T obj);

public delegate void Action<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8>
(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8);

System.Core.dll (.NET Framework 3.5 onwards) is supporting the higher versions of Action delegate. It supports up to 16 input parameters.

Assembly: System.Core (in System.Core.dll)
Namespace: System

ActionDelegatesNew

public delegate void Action<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, 
in T9, in T10, in T11, in T12, in T13, in T14, in T15, in T16>
(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8,
 T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16);

Func delegate

It comes in generic version only. It encapsulates a method that takes zero or more input parameters and does return a value. System namespace under mscorlib supports up to 8 input parameters.

Assembly: mscorlib (mscorlib.dll)
Namespace: System

FuncDelegate_Old

public delegate TResult Func<out TResult>();
public delegate TResult Func<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, out TResult>
(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8);

System.Core.dll (.NET Framework 3.5) is supporting the higher versions of Func delegate. It supports up to 16 input parameters.

Assembly: System.Core (in System.Core.dll)
Namespace: System

Func_Delegate_New

public delegate TResult Func<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, 
in T9, in T10, in T11, in T12, in T13, in T14, in T15, in T16, out TResult>
(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, 
T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16);

Predicate delegate

Predicate is a special kind of Func delegate which returns a Boolean. It encapsulates a method that has takes one input parameter and returns a Boolean. Predicate is basically identical to Func<T, bool>.

Assembly: mscorlib (in mscorlib.dll)
Namespace: System

Predicate

public delegate bool Predicate<in T>(T obj)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s