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?
All delegate types derive from
System.Delegate(just like all enum types derive fromSystem.Enum), which means they all have all the methods on this page.The noteworthy ones are:
DynamicInvokeGetInvocationListA
staticmethod of theDelegatetype that is very interesting and totally worth knowing about (as it can turn poorly performing reflected code into zippy compiled code) isCreateDelegate.Also:
EqualsandGetHashCode(yes, they are overridden).And until recently I was honestly not aware of the
MethodandTargetproperties, but I can imagine they’d be quite useful in certain specific contexts.