且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

带有可选参数的委托引发运行时异常

更新时间:2022-01-12 23:10:33

请参考一次:
http://***.com/questions/2484226/invoking-eventhandler-generic-targetparametercountexception [ ^ ]
please refer once:
http://***.com/questions/2484226/invoking-eventhandler-generic-targetparametercountexception[^]


如果您知道要调用的方法,则
If you know which method you are calling then
string s = (string)this.Invoke(new MyDelegate(MyMethod), new object[] { 10 });


只是没有意义的


is pointless just do

string s = MyMethod(10);


但是,如果您的方法是动态的,则将其设置为


However if your method is dynamic then it would be set somewhere like

private MyDelegate _mydelegate;

public void SetDelegate(MyDelegate del)
{
   _mydelegate = del;
}


你会用
称呼它


and you would call this by

private void somemethod()
{
     string s = _del(10); //using the defined delegate
}