我理解委托和事件
1:XX导演拍电影的类里面包含电影什么时间上映的isOnline 方方
1 /// <summary> 2 /// 电影的导演类 3 /// </summary> 4 public class Boss 5 { 6 public delegate void EventHanderMove(object sender, AV e); 7 public event EventHanderMove EventMove; 8 public void isOnline(string name,int age, string move) 9 { 10 if (EventMove!=null) 11 { 12 EventMove(this,new AV(name,age,move)); 13 } 14 } 15 }
2:AV女郎的资料(拍戏肯定要潜她们了,哈哈)
1 /// <summary> 2 /// AV演员资料类 3 /// </summary> 4 public class AV:EventArgs 5 { 6 public readonly string name; 7 public readonly int age; 8 public readonly string move; 9 public AV(string name, int age, string move) 10 { 11 this.name = name; 12 this.age = age; 13 this.move = move; 14 } 15 }
3:有人拍片有人看,这是市场趋势例:张先生和秦先生订阅了XX 导演的电影
1 /// <summary> 2 /// 订阅AV的类 3 /// </summary> 4 public class MrZhang { 5 public static void ReceiveMove(object sender, AV e) 6 { 7 string str = "有" + e.name + "主演的电影" + e.move + "她今年才" + e.age + "哦哈哈我喜欢"; 8 Console.WriteLine(str); 9 } 10 } 11 /// <summary> 12 /// 订阅AV的类 13 /// </summary> 14 public class MrQin 15 { 16 public static void ReceiveAVMove(object sender, AV e) 17 { 18 string str = "有" + e.name + "主演的电影" + e.move + "她今年才" + e.age + "哦哈很不错的一个小姑娘我好喜欢"; 19 Console.WriteLine(str); 20 } 21 }
4:XX导演的电影要上映了此时要触发isOnline事件了(此时谁订阅了谁就可以看到XX导演电影了,当然质量怎么样当事人知道了。)
1 class Program 2 { 3 public static void Main(string[] args) 4 { 5 Boss boss = new Boss(); 6 boss.EventMove += new Boss.EventHanderMove(MrZhang.ReceiveMove);//MrZhang订阅了 7 boss.EventMove += new Boss.EventHanderMove(MrQin.ReceiveAVMove);//MrQin也订阅了 8 boss.isOnline("仓井空", 20, "要你爽");//上映电影 9 for (int i = 0; i < 100; i++) 10 { 11 Console.WriteLine(i.ToString()); 12 if (i==99) 13 { 14 Console.WriteLine("正在换片请稍等10秒........."); 15 System.Threading.Thread.Sleep(10000);//线程休息10秒 16 Console.WriteLine("搞定开始播放"); 17 boss.isOnline("小泽玛利亚",20,"私人伙伴"); 18 } 19 } 20 Console.ReadKey(); 21 } 22 }