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.
Func, Action and Predicate are generic inbuilt delegates present in System namespace. All three can be used with method, anonymous method and lambda expression.
Delegates allow methods to be passed as parameters. Delegates can be used to define callback methods. Delegates can be chained together; for example, multiple methods can be called on a single event. Methods don't have to match the delegate type exactly.
A delegate is a reference type variable that holds the reference to a method. The reference can be changed at runtime. Delegates are especially used for implementing events and the call-back methods.
A delegate can define its own type parameters. Code that references the generic delegate can specify the type argument to create a closed constructed type, just like when instantiating a generic class or calling a generic method, as shown in the following example: C# Copy.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With