animal.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace work090
{
//委托
public delegate void AnimalEventHandler();
public class Animal
{
public event AnimalEventHandler OnFly;
public void Fly()
{
OnFly();
}
}
}
webform1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace work090
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
work090.Animal bird = new Animal();
bird.OnFly += bird_OnFly;
bird.Fly();
}
void bird_OnFly()
{
Response.Write("飞翔");
}
}
}