.NET框架中的委托和事件

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System.Text.RegularExpressions; namespace _.net之美
{
class Program
{
static void Main(string[] args)
{
Heater heater = new Heater();
Alert alert = new Alert();
heater.boiled += alert.AlertTemperature;
heater.boiled += Display.ShowMsg;
heater.BoilWater();
Console.ReadKey();
}
} public class Heater
{
private readonly string area="ChengDu";
public string Area { get { return area; } } private readonly string type = "";
public string Type { get { return type; } } private int temperature; public delegate void BoiledEventHandle(object sender, BoiledEventArgs args);
public event BoiledEventHandle boiled; public void BoilWater()
{
for (int i = ; i <= ; i++)
{
temperature = i;
BoiledEventArgs e = new BoiledEventArgs(temperature);
if (temperature > )
{
OnBoiled(e);
}
}
} private void OnBoiled(BoiledEventArgs e)
{
if (boiled != null)
boiled(this, e);
} public class BoiledEventArgs
{
private readonly int temperature;
public BoiledEventArgs(int temperature)
{
this.temperature = temperature;
} public int Temperature { get { return this.temperature; } }
}
} public class Alert
{
public void AlertTemperature(object sender, Heater.BoiledEventArgs e)
{
Heater heater = (Heater)sender;
Console.WriteLine("Area:{0},Type:{1}", heater.Area, heater.Type);
Console.WriteLine("水快烧开了!");
}
} public class Display
{
public static void ShowMsg(object sender, Heater.BoiledEventArgs e)
{
Heater heater = (Heater)sender;
Console.WriteLine("Area:{0},Type:{1}", heater.Area, heater.Type);
Console.WriteLine("当前温度:{0}", e.Temperature);
}
}
}

委托进阶

第3章 C#中的委托和事件的更多相关文章

  1. 【转载】C# 中的委托和事件(详解:简单易懂的讲解)

    本文转载自http://www.cnblogs.com/SkySoot/archive/2012/04/05/2433639.html C# 中的委托和事件(详解) C# 中的委托和事件 委托和事件在 ...

  2. C# 中的委托和事件(详解)

    C# 中的委托和事件 委托和事件在 .NET Framework 中的应用非常广泛,然而,较好地理解委托和事件对很多接触 C# 时间不长的人来说并不容易.它们就像是一道槛儿,过了这个槛的人,觉得真是太 ...

  3. 【转载】C# 中的委托和事件(详解)

    <div class="postbody"> <div id="cnblogs_post_body" class="blogpost ...

  4. C# 中的委托和事件

    觉得这篇文章写的非常好,大神之作,由简入繁,对我这种初学者来说帮忙很大,特此留存下. 摘自:http://tracefact.net/CSharp-Programming/Delegates-and- ...

  5. C# 中的委托和事件(转)

    引言 委托 和 事件在 .Net Framework中的应用非常广泛,然而,较好地理解委托和事件对很多接触C#时间不长的人来说并不容易.它们就像是一道槛儿,过了这个槛的人,觉得真是太容易了,而没有过去 ...

  6. C# 中的委托和事件(转载)

    引言 委托 和 事件在 .Net Framework中的应用非常广泛,然而,较好地理解委托和事件对很多接触C#时间不长的人来说并不容易.它们就像是一道槛儿,过了这个槛的人,觉得真是太容易了,而没有过去 ...

  7. 【转】C# 中的委托和事件

    阅读目录 C# 中的委托和事件 引言 将方法作为方法的参数 将方法绑定到委托 事件的由来 事件和委托的编译代码 委托.事件与Observer设计模式 .Net Framework中的委托与事件 总结 ...

  8. 分分钟用上C#中的委托和事件之窗体篇

    上次以鸿门宴的例子写了一篇名为<分分钟用上C#中的委托和事件>的博文,旨在帮助C#初学者迈过委托和事件这道坎,能够用最快的速度掌握如何使用它们.如果觉得意犹未尽,或者仍然不知如何在实际应用 ...

  9. 《C#高级编程》学习笔记------C#中的委托和事件(续)

    本文转载自张子阳 目录 为什么要使用事件而不是委托变量? 为什么委托定义的返回值通常都为void? 如何让事件只允许一个客户订阅?(事件访问器) 获得多个返回值与异常处理 委托中订阅者方法超时的处理 ...

随机推荐

  1. [BZOJ 3209]花神的数论题

    一道简单的数位 dp 题 但是脑子里只有 __builtin_popcountll 了呢(自重) 看完题解后很快就理解了,而且有一种这么简单的题居然没想到做法真是不应该唉~的感觉 用 f[i] 表示 ...

  2. EDIUS校正颜色轮的方法

    小伙伴平时肯定能在网络上看到各种各样的视频吧,它们有的搞笑,有的炫酷,有的教育......那么你们有没有想过做出带有自己创意的视频呢?其实这个愿望很容易实现的,学好一款视频编辑软件就可以了.今天小编就 ...

  3. Python之paramiko基础

    一.Paramiko模块 paramiko是一个自由和开放源码模块使用,实现SSH2协议安全(认证和加密)连接到远程计算机. 二.windwos下安装paramiko模块 #在DOS命令行执行如下命令 ...

  4. SQL SERVER调用textcopy写文件

    SET @PATH = 'textcopy /S ' + @LServer + ' /U '+ @LUser + ' /P '+ @LPass + ' /D '+ @LDB + ' /T '+@tab ...

  5. linux系统的初化始配置 IP 主机名 防火墙 selinux

    本次内容包括Linux:ip.主机名.关闭firewalld与selinux 开机临时生效和永久生效 ------------------------------------------------- ...

  6. .NET微信自定义分享标题、缩略图、超链接及描述的设置方法

    前端Js引用: <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script> ...

  7. bzoj3822: 文学

    Description 巨酱和主席是一对好朋友.他们都很喜欢读书,经常一起阅读相关领域书籍,进行系统的学习.一天主席列出了一份列表,里面共 p 本书,其中不乏<约翰克里斯多夫>,<名 ...

  8. myeclipse的debug模式中breakpoint窗口怎么调出来

    myeclipse的debug模式中breakpoint窗口怎么调出来? 解决办法: window-->show view-->breakpoints.   如下:

  9. NET异常 在 getsockopt 或 setsockopt 调用中指定的一个未知的、无效的或不受支持的选项或层次。

    var Listener = new TcpListener(IPAddress.Any, port); Listener.AllowNatTraversal(true); // 在WIN8中调试没问 ...

  10. 继承extends

    class Person{ String name; int age; void eat(){ System.out.println("吃饭"); } void introduce ...