public delegate void CatListeningHandler();

class Cat

   

        public event CatListeningHandler CatCry

 

        public void Cry()

        {

            Console.WriteLine("Meow~~~");

            OnCry();

        }

 

        protected virtual void OnCry()

        {

            if (CatCry != null)

            {

                CatCry();

            }

        }

    }

 

    class Mouse

    {

        public void Run()

        {

            Console.WriteLine("Mouse run away……");

        }

}

    class Program

    {

        static void Main(string[] args)

        {

 

            Cat obj_cat = new Cat();

            Mouse obj_mouse = new Mouse();

            obj_cat.CatCry += new CatListeningHandler(obj_mouse.Run);

            obj_cat.Cry();

            Console.ReadLine();

        }

    }

 

相关文章:

  • 2022-12-23
  • 2021-06-19
  • 2022-12-23
  • 2021-12-27
  • 2021-08-17
  • 2021-06-07
  • 2021-09-04
猜你喜欢
  • 2022-01-21
  • 2022-12-23
  • 2021-06-08
  • 2021-07-01
  • 2021-09-28
相关资源
相似解决方案