namespace 委托练一练
{   
    //public delegate void Weituo(string x,int i);//定义委托
    //public delegate void Niming(int z);//定义一个委托(用来匿名的)
    //public delegate int Fanhui(int z);//带返回值的
    public delegate int Goes(int i, int j); //lambda表达式
 
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Weituo x = new Weituo(Show);
            //x("吗",1);
            //Niming y = new Niming(delegate(int z) { textBox1.Text = "匿名委托"+z; });//匿名委托
            //y(3);
            //Fanhui f = new Fanhui(delegate(int z) { textBox1.Text = "你好"+z; return z; });//带返回值的
            //f(2);
            Goes g = (int i, int j) => { textBox1.Text = "你好"+(i + j).ToString(); return i + j; };
            g(100, 200); //lambda表达式
 
} public void Show(string x,int i) { textBox1.Text = "你好"+x+i.ToString(); } } }

 

相关文章:

  • 2022-02-27
  • 2022-12-23
  • 2021-07-28
  • 2021-09-25
  • 2021-12-09
  • 2021-08-04
  • 2022-01-18
  • 2022-01-03
猜你喜欢
  • 2021-10-04
  • 2022-02-02
  • 2022-12-23
  • 2022-12-23
  • 2021-08-07
  • 2021-11-20
相关资源
相似解决方案