Friday, November 2, 2012

Delegation

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)




 
  1. First declare delegate processMath which have signature same of method1 & method2
  2. Declare variable process of the delegate (this variable will have type as delegate)
  3. 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 .
  4. Finally we will call the variable which represent the method and we will pass the parameters.

No comments:

Post a Comment

SSRS - How to Parameterizing the SQL Query

We need to create separated dataset to handle the pre defined list in that dataset we will use simple select statement to define the li...