kof*_*cii 2 .net c# delegates asynchronous
我很好奇委托方法存在什么?例如,我知道异步方法调用,如下所示:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
这是"BeginInvoke()"和"EndInvoke()"方法,但是还有其他任何委托方法吗?
所有委托类型派生自System.Delegate(就像所有枚举类型派生自的System.Enum),这意味着它们都拥有此页面上的所有方法.
值得注意的是:
DynamicInvoke
GetInvocationList
一种非常有趣并且完全值得了解static的Delegate类型的方法(因为它可以将表现不佳的反射代码转换为zippy编译代码)CreateDelegate.
另外:Equals和GetHashCode(是的,它们被覆盖).
直到最近,我才真正意识到这些Method和Target属性,但我可以想象它们在某些特定情况下非常有用.
| 归档时间: |
|
| 查看次数: |
221 次 |
| 最近记录: |