Delegation is type
which can be used to save reference to method (procedure /function).
Since delegation is a type so we should think it is something like data
types then we can define variable of that delegate (type) and then we
can use this variable as reference to method.
The declaration of the delegation same of the declaration of the method with one exception delegation will not have body (no code), and the declaration represent signature of method so it will contain return value and parameters.
Delegate <return Type> <MethodName> (type Prameter1,type Pramter2)
Delegate double processMath(double param1 , double param2)
- First declare delegate processMath which have signature same of method1 & method2
- Declare variable process of the delegate (this variable will have type as delegate)
- Initiate the variable process by using the contractor, process= new processMath (Divide) ,
as we see when we Initiate the variable we pass the method name as
parameter which not match with the declaration of the delegation, but
that method has signature same as of the delegation .
- Finally we will call the variable which represent the method and we will pass the parameters.