微软虚拟化之五 Hyper-V独门绝技
2011-04-16 23:48
162 查看
//业务逻辑:我有一个防盗器,当我的汽车其他人启动时,警告我汽车被启动了
//Program.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace EventExample
{
class Program
{
static void Main(string[] args)
{
Car cr = new Car();//实例化类
cr.carStartEvent += new Car.CarStartDelegate(cr_carStartEvent);//订阅汽车启动事件
Console.WriteLine("汽车被别人启动了...");
cr.myCarStart();//触发汽车启动的方法
Console.Read();
}
static void cr_carStartEvent(string startwarming)
{
Console.WriteLine(startwarming);//接收到来自汽车的通知,显示在屏幕上
}
}
}
//Car.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace EventExample
{
class Car
{
public delegate void CarStartDelegate(string startwarming);//通过委托通知订阅者
public event CarStartDelegate carStartEvent;//声明事件
public void myCarStart()
{
carStartEvent("通知:汽车被启动了!");
}
}
}
本文出自 “MyCode” 博客,请务必保留此出处http://snowleung.blog.51cto.com/935227/226716
//Program.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace EventExample
{
class Program
{
static void Main(string[] args)
{
Car cr = new Car();//实例化类
cr.carStartEvent += new Car.CarStartDelegate(cr_carStartEvent);//订阅汽车启动事件
Console.WriteLine("汽车被别人启动了...");
cr.myCarStart();//触发汽车启动的方法
Console.Read();
}
static void cr_carStartEvent(string startwarming)
{
Console.WriteLine(startwarming);//接收到来自汽车的通知,显示在屏幕上
}
}
}
//Car.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace EventExample
{
class Car
{
public delegate void CarStartDelegate(string startwarming);//通过委托通知订阅者
public event CarStartDelegate carStartEvent;//声明事件
public void myCarStart()
{
carStartEvent("通知:汽车被启动了!");
}
}
}
本文出自 “MyCode” 博客,请务必保留此出处http://snowleung.blog.51cto.com/935227/226716
相关文章推荐
- 微软虚拟化之五――Hyper-V独门绝技
- 微软虚拟化之五——Hyper-V独门绝技 推荐
- UltraLAB台式图形工作站(独门绝技~多核+超高频~极速计算工作站H490介绍)
- 阿里独门绝技:如何运用H.265降低30%的视频传输成本
- 独门绝技解决 ESXI6.0 时间(时区)显示不一致
- 独门绝技修改注册表
- 微软虚拟化之一Hyper-V 2.0的安装及基本配置
- 预算为0如何拉用户?类类教你5个独门绝技,并说说一些陷阱!
- 独门安装卸载绝技:巧用Rundll32
- 微软虚拟化-构建高可用性的Hyper-V虚拟化平台(二)
- 独门绝技:一招克死所有病毒(转贴,没有用过)
- 微软虚拟化产品Hyper-V 2.0蓄势待
- 微软虚拟化产品专家、MVP最新力作,国内第一本Hyper-V管理实践专著!
- 微软虚拟化之一Hyper-V 2.0的安装及基本配置
- 独门绝技:一招克死所有病毒
- 全面分析微软虚拟化技术Hyper-V
- Hyper-V 3 微软虚拟化平台日渐成形
- 预算为0如何拉用户?类类教你5个独门绝技,并说说一些陷阱!
- 微软虚拟化之一Hyper-V R2的安装及基本配置
- IBM BigInsights新增独门绝技:全面支持Hadoop On Power!