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";
}
}
委托是个类,事件是委托的一个实例,存在后是个具体的指针