我很好奇委托方法存在什么?例如,我知道异步方法调用,如下所示:
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);
}
}
以下是“BeginInvoke()”和“EndInvoke()”方法,但是还有其他任何委托方法吗?
答案 0 :(得分:6)
所有委托类型都来自System.Delegate
(就像所有来自System.Enum
的枚举类型一样),这意味着它们都拥有this page上的所有方法。
值得注意的是:
DynamicInvoke
GetInvocationList
static
类型的Delegate
方法非常有趣并且完全值得了解(因为它可以将效果不佳的反映代码转换为zippy编译代码)是CreateDelegate
。
另外:Equals
和GetHashCode
(是的,它们被覆盖)。