Delegate 簡易練習
public partial class _Default : System.Web.UI.Page
{
delegate string demo(string Name);
class Say
{
public static string SayHello (string name)
{
return string.Format("Hello {0}", name);
}
public static string HelloHey (string name)
{
return string.Format("Hey {0}", name);
}
}
protected void btnRun_Click(object sender, EventArgs e)
{
demo d1 = new demo(Say.SayHello);
lblResult.Text = d1("JengTing") + "<br>";
demo d2 = new demo(Say.HelloHey);
lblResult.Text += d2("JengTing") + "<br>";
}
}
沒有留言:
張貼留言