//最后,该模式要求写一个受保护的(protected)虚方法引发事件.方法名必须和事件名一致,以On作为前缀,并接受唯一的EventArgs参数 protected virtual void OnPriceChanged(PriceChangedEventArgs e) { if (PriceChanged != null) { PriceChanged(this, e); } }
static void stock_PriceChanged(object sender, PriceChangedEventArgs e) { //throw new NotImplementedException(); if ((e.NewPrice - e.LastPrice) / e.LastPrice > 0.1M) { Console.WriteLine("Alert,10% stock price increase!"); } }