1.定义个委托和类 //委托 public delegate void ProductEventHandler(Product product);/// <summary> /// 产品 /// </summary> public class Product {public int Id { get; set; }public string Code { get; set; }public string Name { get; set; }private decimal price;public decimal Price{get { return price; }set{price = value;if(price > 10){//事件触发ProductChanged.Invoke(this);}}}//事件public event ProductEventHandler ProductChanged;/// <summary>/// 模拟业务的异常记录方法/// </summary>/// <param name="product"></param>public void RecordException(Product product){Console.WriteLine($"事件被触发,价格波动异常:{product.Price}");} } 2.调用(通过属性值得变化去触发事件) var product = new Product(); product.ProductChanged += product.RecordException; while (true) {Console.Write("请输入价格:");var num = Convert.ToDecimal(Console.ReadLine());product.Price = num; }