Delegate: - Delegate is an abstract pointer to a function or method. In other words you can create a pointer which points to a method or function and then pass that pointer wherever you wish and invoke the function / method.
Multicast Delegate: - Normally when you create a delegate, your delegate points to only one function or method. In case you want to point multiple functions and invoke them sequentially, you need to use the multicast delegate.
To point to multiple function using delegate pointer we need to use “+=” sign as shown in the below code snippet.
How can we create a delegate?
Creating a delegate is four step process:-
- Declare a delegate.
- Create an object reference.
- Point the reference to the method.
- Invoke the method via the delegate.
Below is the code snippet for the same.
Also see another .NET OOPS interview questions video on difference between Abstraction and Encapsulation: -