public class Operation
{
public int Add ( int a , int b )
{
return (a+b);
}
}
We have to call above method using delegate
Steps below :
- Declare a delegate : public delegate int DelAdd ( int a , int b );
- Instantiate a delegate : Operation obj = new Operation() ; DelAdd objDel = new DelAdd(obj.Add);
- 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:
Post a Comment