Func delegate with no return type

Marcel Lamothe picture Marcel Lamothe · May 27, 2009 · Viewed 214.5k times · Source

All of the Func delegates return a value. What are the .NET delegates that can be used with methods that return void?

Answer

Jason picture Jason · May 27, 2009

All Func delegates return something; all the Action delegates return void.

Func<TResult> takes no arguments and returns TResult:

public delegate TResult Func<TResult>()

Action<T> takes one argument and does not return a value:

public delegate void Action<T>(T obj)

Action is the simplest, 'bare' delegate:

public delegate void Action()

There's also Func<TArg1, TResult> and Action<TArg1, TArg2> (and others up to 16 arguments). All of these (except for Action<T>) are new to .NET 3.5 (defined in System.Core).