views:

70

answers:

1

I'm curious what delegates methods exists? For instance I'm aware of Asynchronous method calls, like this:

class Program {
   // define a delegate
   delegate int MyDelegate(String s);

   static void Main(string[] args) {
      // create the delegate
      MyDelegate del = new MyDelegate(myMethod);

      // invoke the method asynchronously
      IAsyncResult result = del.BeginInvoke("foo", null, null);

      // get the result of that asynchronous operation
      int retValue = del.EndInvoke(result);

      }
   }

Here are "BeginInvoke()" and "EndInvoke()" methods, but is there any other delegates methods?

+6  A: 

All delegate types derive from System.Delegate (just like all enum types derive from System.Enum), which means they all have all the methods on this page.

The noteworthy ones are:

DynamicInvoke
GetInvocationList

A static method of the Delegate type that is very interesting and totally worth knowing about (as it can turn poorly performing reflected code into zippy compiled code) is CreateDelegate.

Also: Equals and GetHashCode (yes, they are overridden).

And until recently I was honestly not aware of the Method and Target properties, but I can imagine they'd be quite useful in certain specific contexts.

Dan Tao
Thanks a lot. I have another question. I followed your link, and in MulticastDelegate Class reference in msdn library, is mentioned that "common language runtime provides two special methods: BeginInvoke and EndInvoke". Just of a curiosity, do you know where are declared those methods?
kofucii