陋室铭
永远也不要停下学习的脚步(大道至简至易)

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        a a1 = new a();
        a1.DelegateEvent+=new delegateExample(a1_DelegateEvent);
        a1.A1();

        b b1 = new b();
        b1.myDelegate = new delegateExample(a1_DelegateEvent);
        b1.B1();
    }
    public string a1_DelegateEvent(string Classname)
    {
        return Classname;
    }
}
public delegate string delegateExample(string Classname);
public class a
{
    public event delegateExample DelegateEvent;
    public string A1()
    {
        if (DelegateEvent != null)
        {
            DelegateEvent("a");
        }
        return "a1";
    }

}

public class b
{
    public delegateExample myDelegate;
    public string B1()
    {
        if (myDelegate != null)
        {
            myDelegate("b");
        }
        return "b1";
    }

}
委托是个类,事件是委托的一个实例,存在后是个具体的指针

posted on 2008-06-30 11:42  宏宇  阅读(336)  评论(2编辑  收藏  举报