1、定义
public event EventHandler<BoatChanged> BoatChangedEvent; //BoatChanged为类,可传递参数
public event EventHandler DataChanged; //无参数传递
2、发送
if (this.BoatChangedEvent != null) { this.BoatChangedEvent(null, new BoatChanged(this.Name)); }
if (this.DataChanged != null) { this.DataChanged(this, EventArgs.Empty); }
3、类定义
点击查看代码
public class BoatChanged: EventArgs
{
public BoatChanged(string name)
{
this.TimeStamp = DateTime.Now;
this.Name= name;
}
public DateTime TimeStamp { get; }
public string Name{ get; private set; }
}