- class Program
- {
- static void Main(string[] args)
- {
- People people = new People();
- Cat cat = new Cat();
- Mice mice = new Mice();
- cat.OnMew += mice.Flee;
- cat.OnMew += people.Wake;
- cat.Mew();
- }
- }
- public class Cat
- {
- public delegate void EventMew();
- public event EventMew OnMew;
- public void Mew()
- {
- Console.WriteLine("maio....");
- OnMew();
- }
- }
- public class People
- {
- public void Wake()
- {
- Console.WriteLine("谁?");
- }
- }
- public class Mice
- {
- public void Flee()
- {
- Console.WriteLine("老鼠吓跑了....");
- }
- }
一道事件委托面试题 - 猫叫老鼠跑主人醒
最新推荐文章于 2024-05-04 20:47:36 发布