代码之家  ›  专栏  ›  技术社区  ›  kofucii

dot.net委托有多少种方法?

  •  2
  • kofucii  · 技术社区  · 14 年前

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

    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 回复  |  直到 13 年前
        1
  •  6
  •   Dan Tao    14 年前

    所有委托类型都派生自 System.Delegate (就像所有枚举类型派生自 System.Enum 这意味着他们都有所有的方法 this page .

    值得注意的是:

    DynamicInvoke
    GetInvocationList

    static 方法 Delegate 非常有趣并且完全值得了解的类型是 CreateDelegate .

    也: Equals GetHashCode (是的,它们被覆盖)。

    直到最近我才真正意识到 Method Target 属性,但我可以想象它们在某些特定的上下文中非常有用。