Events Sample Code(2)

王朝c#·作者佚名  2006-12-17
宽屏版  字体: |||超大  

Events Sample Code(2)

Events Sample Code(2) using System;

namespace ConsoleApp_CSXP

{

class 小弟

{

//1.聲明事件委託

public delegate void 被人扁(object sender, EventArgs e);

//2.聲明事件實例

public event 被人扁 挨扁;

//3.包含事件

private void 挨扁了(EventArgs e)

{

if(this.挨扁 != null)

this.挨扁(this, e);

}

//4.觸發事件

public void 被扁()

{

Console.WriteLine('被扁ing...');

this.挨扁了(EventArgs.Empty);

}

}

class 我

{

private 小弟 我小弟 = null;

public 我(小弟 小小弟)

{

this.我小弟 = 小小弟;

//註冊事件

this.我小弟.挨扁 += new 小弟.被人扁(this.担心);

}

public void 担心(object sender, EventArgs e)

{

Console.WriteLine('我担心');

}

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有