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(); } } }