tags:

views:

917

answers:

5

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.

+1  A: 

Goto Reflector Search for System.MulticastDelegate and check the derived types. You will get list of all the Delegates you are looking for.

nils_gate
Well, that gives a complete list of delegates. It doesn't give the most useful or important ones, which is what the OP was after I think.
Jon Skeet
+7  A: 

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
Jon Skeet
It does make you wonder though. If generics and Func / Action were available in 1.0, would we have any other delegate types?
JaredPar
It's an interesting question. I rather like Predicate<T> as a more meaningful name than Func<T, bool> for instance - if it weren't for the overloads of Where etc to take Func<T, int, bool> it would be a better fit for LINQ. Specifying type arguments everywhere can hurt readability.
Jon Skeet
+1  A: 

I like to use Predicate<T> which is equivalent to Func<T, bool>

Brian Genisio
A: 

I use WaitCallback and ThreadStart often enough for them to get a mention.

If you know the signature of the delegate you're after, but you don't know if there's an existing delegate with that signature that you can use, you can follow these instructions on my blog to find one.

HTH, Kent

Kent Boogaart
A: 

System.Windows.ValidateValueCallback which represents a method used as a callback that validates the effective value of a dependency property.

Read More: MSDN: ValidateValueCallback Delegate

M. Jahedbozorgan