您的位置:首页 > 其它

微软虚拟化之五 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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: