[ASP.NET] 事件与委托的处理

     放一段C#中基本的利用事件与委托的程序,执行平台 .net控制台程序

 1 using  System;
 2 using  System.Collections.Generic;
 3 using  System.Text;
 4
 5 namespace  practise2
 6 {
 7    public delegate void DelHandler( object sender );            //委托的申明
 8    class Program
 9    {
10        static void Main(string[] args)
11        {
12            Heater heater = new Heater();
13        }

14    }

15    public class Heater
16    {
17        public event DelHandler temEvent;
18        public Heater()
19        {
20            temEvent += new DelHandler(Alarm.MakeAlert);           //事件与委托的绑定,委托与处理函数绑定
21            System.Threading.Thread.Sleep(1000);
22            temEvent(this);                                        //事件的触发,这里规定刚开始实例化就触发
23        }

24
25    }

26    
27
28    public class Alarm
29    {
30        static public void MakeAlert(object sender)                 //处理函数,参数要和委托申明一样
31        {
32            Display.showMessage();
33        }

34    }

35    public class Display
36    {
37        static public void showMessage()
38        {
39            Console.Write("KAILE");
40        }

41    }

42}

43

转载于:https://www.cnblogs.com/felixfang/archive/2009/08/19/1550002.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值