Standard delegates in C#

Tarion picture Tarion · Apr 8, 2009 · Viewed 20.6k times · Source

There are some Delegates predefined in C#

I know these:

EventHandler // Default event callbacks
EventHandler<T> // Default event callbacks with custom parameter (inheriting from EventArgs)
Action // Function without return value and without parameter
Action<T1, T2, T3, T4> // Function without return value and 1-4 parameters
Func<T1, T2, T3, T4, TResult> // Methos with 0-4 parameters and one result type
Predicate<T> // equivalent to Func<T, bool>

There are many more for special cases and generated form parts of the framework, but these are often good to use in self written code.

If you know some more useful add them. Otherwise this is answered.

Answer

Jon Skeet picture Jon Skeet · Apr 8, 2009

They're not predefined in C#. They're defined by the framework.

The Action and Func delegate families are wider than you've shown - they go up to

Action<T1, T2, T3, T4>

and

Func<T1, T2, T3, T4, TResult>

Another common-ish one in .NET 2.0 for list manipulation (before LINQ) is Predicate<T>.

For working with threads:

ThreadStart
ParameterizedThreadStart
WaitCallback
TimerCallback
AsyncCallback