Marcel Lamothe Marcel Lamothe - 1 month ago 14
C# Question

Func delegate with no return type

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

Answer

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 four arguments). All of these (except for Action<T>) are new to .NET 3.5 (defined in System.Core).