110,539
社区成员
发帖
与我相关
我的任务
分享
...............
private delegate void MyMethodHandler();//delegate
private event MyMethodHandler MyMethodEvent;//event
private void Method()
{
MyMethodEvent+=Method1();
MyMethodEvent+=Method2();
MyMethodEvent+=Method3();
MyMethodEvent+=Method4();
MyMethodEvent+=Method5();
Delegate[] delegates = MyMethodEvent.GetInvocationList();
for (int i = 0; i < delegates.Length; i++)
{
MethodInfo methodInfo = delegates[i].Method;
methodInfo.Invoke(null, null);//这里有异常,未处理TargetException,非静态方法需要一个目标。
}
}
private viod Method1(){//nothing to do...this is demo...}
private viod Method2(){//nothing to do...this is demo...}
private viod Method3(){//nothing to do...this is demo...}
private viod Method4(){//nothing to do...this is demo...}
private viod Method5(){//nothing to do...this is demo...}
..............
methodInfo.Invoke(null, null);//这里第一个参数是这个委托的实例,后面的是参数.
...............
private delegate void MyMethodHandler();//delegate
private event MyMethodHandler MyMethodEvent;//event
private void Method()
{
MyMethodEvent+=Method1();
MyMethodEvent+=Method2();
MyMethodEvent+=Method3();
MyMethodEvent+=Method4();
MyMethodEvent+=Method5();
Delegate[] delegates = MyMethodEvent.GetInvocationList();
for (int i = 0; i < delegates.Length; i++)
{
MethodInfo methodInfo = delegates[i].Method;
methodInfo.Invoke(this, null);//这里有异常,TargetInvocationException,调用的目标发生了异常。
}
}
private viod Method1(){//nothing to do...this is demo...}
private viod Method2(){//nothing to do...this is demo...}
private viod Method3(){//nothing to do...this is demo...}
private viod Method4(){//nothing to do...this is demo...}
private viod Method5(){//nothing to do...this is demo...}
private viod Method6(){//nothing to do...this is demo...}
private viod Method7(){//nothing to do...this is demo...}
private viod Method8(){//nothing to do...this is demo...}
private viod Method9(){//nothing to do...this is demo...}
private viod Method10(){//nothing to do...this is demo...}
private viod Method11(){//nothing to do...this is demo...}
private viod Method12(){//nothing to do...this is demo...}
private viod Method13(){//nothing to do...this is demo...}
..............