Blog from Saravanan Arumugam

Let us talk about Technologies

Facts about Action and Func Delegate


We can notice many methods take Action,Fun or any specific delegate as parameters.

When an Action Delegate or Func Delegate appear, what do they mean? What do they signal to the developer?

 

Action Delegate

Action delegate, no matter how many parameters it can take, it returns void.

public delegate void Action<in T1, in T2>(
	T1 arg1,
	T2 arg2
)

There are 17 versions of Action delegates ranging from no type parameters up to 16 type parameters. Action, Action<T>, Action<T1,T2>…etc.

Func Delegate

Func delegate in contrast, always returns the a value of TResult type.

For example, following is the syntax of a Func with nine arguments. This delegate would expect a value of TResult type.

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

Like Action delegates, Func has 17 versions ranging from no type parameters up to 16 type parameters. Func<TResult>, Action<T, TResult>, Action<T1,T2,TResult >…etc.

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: