What are the different types of Delegates?

The Different types of Delegates are:

Single Delegate – A delegate which can call a single method.
Multicast Delegate – A delegate which can call multiple methods. + and – operators are used to subscribe and unsubscribe respectively.
Generic Delegate – It does not require an instance of delegate to be defined. It is of three types, Action, Funcs and Predicate.

Action– In the above example of delegates and events, we can replace the definition of delegate and event using Action keyword. The Action delegate defines a method that can be called on arguments but does not return a result
Public delegate void deathInfo();

Public event deathInfo deathDate;
//Replacing with Action//
Public event Action deathDate;

Action implicitly refers to a delegate.

Func – A Func delegate defines a method that can be called on arguments and returns a result.
Func <int, string, bool> myDel is same as delegate bool myDel(int a, string b);

 Predicate – Defines a method that can be called on arguments and always returns the bool.
Predicate<string> myDel is same as delegate bool myDel(string s);

Post a Comment

0 Comments