How many methods dot.Net delegates have?
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 resu开发者_如何学Pythonlt 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 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.
精彩评论