Func和Action

private void button7_Click(object sender, EventArgs e)
        {
            Action<int, int> action = (x, y) => {
                MessageBox.Show((x+y).ToString());
            };
            action(1, 2);
        }

        private void button11_Click(object sender, EventArgs e)
        {
            Action<int, int> action = delegate(int x, int y)
            {
                MessageBox.Show((x + y).ToString());
            };
            action(1, 2);
        }

        private void button8_Click(object sender, EventArgs e)
        {
            Func<int, int, int> func = (x, y) =>
            {
                return x + y;
            };
            int result = func(1, 2);
            MessageBox.Show(result.ToString());
        }

        private void button9_Click(object sender, EventArgs e)
        {
            Action action = delegate()
            {
                MessageBox.Show("Hello.");
            };
            action();
        }

        private void button10_Click(object sender, EventArgs e)
        {
            Action action = () =>
            {
                MessageBox.Show("Hello.");
            };
            action();
        }
posted @ 2010-12-13 16:14  RobotTech  阅读(382)  评论(0编辑  收藏  举报