コード例 #1
0
        /// <summary>
        /// 关联
        /// </summary>
        public static void Init()
        {
            var     buyer = new Buyer();
            IphoneX phone = new IphoneX()
            {
                Price = 10000
            };

            phone.DiscountHandler += buyer.Buy;

            //改了属性的价格,降价了,此时会触发事件的执行
            phone.Price = 2000;
        }
コード例 #2
0
 //参数需要和eventhandler参数一致
 public void Buy(object?sender, EventArgs e)
 {
     IphoneX phone = (IphoneX)sender;
 }