| Define delegates with example and its types
There are certain condition when we need to pass a function as a parameter. Then to handle this a callback function and event handler comes into picture. Delegate is used to implement event and call-back methods. Below are the certain defination of delegates:-
(1)Delegate is a type which represents a references to a methods with some specific parameter list and return type.
(2)Delegate in c# is similar to function pointers of C++ but delegates are always type safe. And we can pass methods as parameters to delegate and allow delegate to point to the method and delegate used to define callback methods and implement event handling.
(3)Delegate is reference to a method its works like pointer in c and c++. But it is Secured, object-oriented and Type-safe then function pointer.
(4)Delegates are a .NET object which points to a method and its matches to a sepcific signature. And delegate can be used to invoke method.
With above 4 definition we got the idea what is delegate and now we will get types of delegates:-
(A)Single Cast Delegate
(B)Multi Cast Delegate
(A)Single Cast Delegate
Here we can refer only single method at one time. SingleCast Delegate refers only to a single method with the matching signature. And this is drived from System.Delegate class.
(B)Multi Cast Delegate
WHen we can refers multiple method at one time and signautre should be the same.
Syntax for declaring Delegates is given below
public delegate returntype delegatename(datatype varname); | | |