dot.Net代表有多少种方法?

时间:2010-08-26 19:51:35

标签: c# .net asynchronous delegates

我很好奇委托方法存在什么?例如,我知道异步方法调用,如下所示:

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()”方法,但是还有其他任何委托方法吗?

1 个答案:

答案 0 :(得分:6)

所有委托类型都来自System.Delegate(就像所有来自System.Enum的枚举类型一样),这意味着它们都拥有this page上的所有方法。

值得注意的是:

DynamicInvoke
GetInvocationList

static类型的Delegate方法非常有趣并且完全值得了解(因为它可以将效果不佳的反映代码转换为zippy编译代码)是CreateDelegate

另外:EqualsGetHashCode(是的,它们被覆盖)。

直到最近,我才真正意识不到MethodTarget属性,但我可以想象它们在某些特定情况下非常有用。