Beispiel #1
0
        public static event EventHandler <MyArgEventsArgs> Counted2; // 使用泛型好处:不需要强转类型了
        public void DoCount()
        {
            MyArgEventsArgs args = new MyArgEventsArgs();

            args.Value = 9;
            Counted?.Invoke(this, args); // this:表示调用本方法的实例对象
            Counted2?.Invoke(this, args);
        }
Beispiel #2
0
        private void Count(object source, EventArgs e)
        {
            MyArgEventsArgs args = (MyArgEventsArgs)e;

            Console.WriteLine(args.Value);
        }
Beispiel #3
0
 private void Count2(object sender, MyArgEventsArgs e)
 {
     Console.WriteLine(e.Value);
 }