zoukankan      html  css  js  c++  java
  • 委托和事件温习

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace TestEvent
    {
        class MyClass
        {
            public delegate void CompletedEventHandler();
    
            public event CompletedEventHandler WorkCompleted;
    
    
            public void Fire()
            {
                if (this.WorkCompleted != null)
                {
                    this.WorkCompleted();
                }
    
             
            }
        }
        class Program
        {
            static void TestEvent()
            {
                Console.WriteLine("test event");
            }
    
            static void TestEvent2()
            {
                Console.WriteLine("test event2");
            }
    
            static void TestEvent3()
            {
                Console.WriteLine("test event3");
            }
            static void TestDelegate()
            {
                Console.WriteLine("test delegate");
            }
    
            static void Main(string[] args)
            {
    
                MyClass myObject = new MyClass();
                myObject.WorkCompleted += TestEvent;
                myObject.WorkCompleted += TestEvent2;
                myObject.WorkCompleted += TestEvent3;
                myObject.WorkCompleted -= TestEvent3;
                myObject.Fire();
                Console.ReadLine();
            }
        }
    }
  • 相关阅读:
    台州 OJ 3847 Mowing the Lawn 线性DP 单调队列
    洛谷 OJ P1417 烹调方案 01背包
    快速幂取模
    台州 OJ 2649 More is better 并查集
    UVa 1640
    UVa 11971
    UVa 10900
    UVa 11346
    UVa 10288
    UVa 1639
  • 原文地址:https://www.cnblogs.com/tiancai/p/6197814.html
Copyright © 2011-2022 走看看