Which class defines BeginInvoke method of a delegate type?

I have a delegate like this:
public delegate int AddDelegate(int op1, int op2, out int result);

And I have a method Add whose code is as below:
        public static int Add(int op1, int op2, out int result)
        {
            Thread.Sleep(3000);
            return (result = op1 + op2);
        }

And then I define a variable named add:
AddDelegate add = new AddDelegate(Add);

Then I can call add.BeginInvoke(6, 42, out result, null, null) method. Now my question is, which ancestor of AddDelegate's firstly define the method BeginInvoke. DeleteGate MulticastDelegate None of them.

I searched in msdn for half an hour and I don't have any clues. So please tell me. I'm new to .net and I got lost in msdn documents.

Thanks in advance.


Answer this question

Which class defines BeginInvoke method of a delegate type?

  • Ed__

    Daniel is correct. When the compiler sees a delegate, it crafts up a class with Invoke, BeginInvoke, and EndInvoke defined on the actual delegate itself. (i.e. Defined on your AddDelegate delegate (really a class). I would wholeheartedly recommend downloading .NET Reflector as it's easier to use than ILDASM.

    Some good articles to get you started with delegates:

    An Introduction to Delegates
    by Jeffrey Richter
    http://msdn.microsoft.com/msdnmag/issues/01/04/net/

    .NET Delegates: Making Asynchronous Method Calls in the .NET Environment
    by Richard Grimes
    http://msdn.microsoft.com/msdnmag/issues/01/08/Async/


  • B.Young

    I opened up Reflector to take a look. The methods Invoke, BeginInvoke and EndInvoke are implemented by the actual delegate, not some base class.

  • Which class defines BeginInvoke method of a delegate type?