I know delegate type is inherited from MulticastDelegate which is in turn inherited from Delegate class.
Also when we create delegate instance it creates three methods (Invoke, BeginInvoke, EndInvoke apart from constructor) with the same signature of the delegate.
I am not able to understand how it is created internally(methods with delegate type signature)?
Thanks in advance.
Lets say for example, we have a delegate like this:
How does the compiler know how to define the Invoke(), BeginInvoke(), and
EndInvoke() methods?
This is the generated class by the compiler:
First, notice that the parameters and return value defined for the Invoke() method exactly
match the definition of the BinaryOp delegate.
The initial parameters to BeginInvoke() members (two integers in our case) are also based on the BinaryOp delegate;
however, BeginInvoke() will always provide two final parameters (of type AsyncCallback and object) that are used to facilitate asynchronous method invocations.
Finally, the return value of EndInvoke() is identical to the original
delegate declaration and will always take as a sole parameter an object implementing the
IAsyncResult interface.