How would you implement delegate calling a method ?

public class Operation
{
   public int Add ( int a , int b )
{
return (a+b);
}
}
We have to call above method using delegate
Steps below :
  1. Declare a delegate : public delegate int DelAdd ( int a , int b );
  2. Instantiate a delegate : Operation obj = new Operation() ; DelAdd objDel = new DelAdd(obj.Add);
  3. Call a delegate : objDel(1,2);
A delegate can be called synchronously as shown above or asynchronously by using BeginInvoke and EndInvoke methods.    What is multicast delegate ?  Multicast delegate contains references to more than one function . Use + operator to add a delegate component to multicast delegate . - operator is used to remove delegate component from multicast delegate

No comments:

Popular Posts