c# 匿名委托

无参:

 if (this.tBReciveInfo.InvokeRequired)
                {
                    this.Invoke(new Action(()=>{
                        this.tBReciveInfo.Text = message.Body.ToString();
                    }));
                }

 

一个参数:

1  private void act()
2  {
3      this.invoke(new Action<string>(s=>{方法(s);}),"参数s")
4  }

万能委托在原有基础上,更进一步,如下:

1 private void act()
2 {
3     this.invoke(new Action<string>(s=>{方法1(参数1);方法2(参数2);……方法n;}),"")
4 }

这里设置s的值为空值,把需要传的参数,直接写在方法里,做到多个参数传值的效果,而不用考虑s的值。

posted @ 2023-05-23 17:41  程序员小白n  阅读(77)  评论(0)    收藏  举报