FlyEventArgs.cs
using System;
namespace ConsoleApplication1
{
/// <summary>
/// FlyEventArgs 的摘要说明。
/// </summary>
public class FlyEventArgs:EventArgs
{
private string status;
public string Status
{
get
{
return status;
}
}
public FlyEventArgs(string m):base()
{
this.status=m;
}
}
}
FlyBird.cs
using System;
namespace ConsoleApplication1
{
public class FlyBird
{
public event FlyEventHandler OnFly;
public void OnFlyHandler(FlyEventArgs e)
{
if(OnFly!=null)
{
OnFly(this,e);
}
}
public FlyBird()
{
}
}
}
Sky.cs
using System;
namespace ConsoleApplication1
{
public delegate void FlyEventHandler(object sender, FlyEventArgs e);
/// <summary>
/// Sky 的摘要说明。
/// </summary>
public class Sky
{
public void onFly(object sender,FlyEventArgs e)
{
Console.Write(e.Status);
}
public Sky(FlyBird bird)
{
bird.OnFly+=new FlyEventHandler(onFly);
}
[STAThread]
static void Main(string[] args)
{
FlyBird bird=new FlyBird();
Sky sky=new Sky(bird);
FlyEventArgs ar=new FlyEventArgs("起飞....");
bird.OnFlyHandler(ar);
}
}
}