星期一, 3月 02, 2015

[C#] Delegate 練習 2

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>";  
    }
}

[C#] Delegate 練習 2

沒有留言:

張貼留言