zoukankan      html  css  js  c++  java
  • [ASP.NET] 事件与委托的处理

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

     1using System;
     2using System.Collections.Generic;
     3using System.Text;
     4
     5namespace 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
  • 相关阅读:
    C#图片无损压缩
    as3.0 动态文本属性大全
    卡​马​克​卷​轴​算​法​研​究​_​地​图​双​缓​冲
    春卷活动心得
    移动端videojs视频插件使用直播流rtmp、hls、http-flv的注意事项
    在Windows2008系统中利用IIS建立FTP服务器
    winform 窗体自适应 根据新窗体大小按比例放缩
    HTTPS抓包
    数据库 事物 锁
    sql 事物 锁 快照(转发的,写的非常好)
  • 原文地址:https://www.cnblogs.com/felixfang/p/1550002.html
Copyright © 2011-2022 走看看