예제 #1
0
        public void 扣钱(object sender, EventArgs e)
        {
            Console.WriteLine("小王:好小子,上班时间胆敢玩游戏");
            Console.WriteLine("小王:看看你小子有多少钱");
            小张 f = (小张)sender;

            Console.WriteLine("小张的钱:" + f.钱.ToString());
            Console.WriteLine("开始扣钱");
            System.Threading.Thread.Sleep(500);
            f.钱 = f.钱 - 500;
            Console.WriteLine("扣完了.现在小张还剩下:" + f.钱.ToString());
        }
예제 #2
0
        static void test_delegate_event()
        {
            Console.WriteLine("场景开始了.");
            //生成小王

            小王 w = new 小王();
            //生成小账
            小张 z = new 小张();

            //指定监视
            z.PlayGame += new PlayGameHandler(w.扣钱);

            //开始玩游戏
            z.玩游戏();

            Console.WriteLine("场景结束");
            Console.ReadLine();
        }