委托简单例子

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class test : System.Web.UI.Page
{
    public delegate string Delegate(string name);
    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text = People("小明", English);
        Label2.Text = People("小阳", Chinese);
    }

    private static string English(string name)
    {
        return "Morning," + name;
    }
    private static string Chinese(string name)
    {
        return "早上好, " + name;
    }
    //注意此方法,它接受一个GreetingDelegate类型的参数,该参数是返回值为空,参数为string类型的方法
    private static string People(string name, Delegate Make)
    {
        return Make(name);
    }
}

 

posted @ 2016-07-04 21:40  叶丶梓轩  阅读(190)  评论(0编辑  收藏  举报