码迷,mamicode.com
首页 > 其他好文 > 详细

委托——不同写法

时间:2015-07-04 19:49:18      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

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

 

委托——不同写法

标签:

原文地址:http://www.cnblogs.com/lk-kk/p/4621139.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!