Events Sample Code(1)
来源:互联网 发布:淘宝买狗狗靠谱吗 编辑:程序博客网 时间:2024/05/16 18:17
using System;
namespace ConsoleApp_CS
{
class 小弟
{
//1.聲明事件實例
public event EventHandler 挨扁;
//2.包含事件
private void 挨扁了(EventArgs e)
{
if(this.挨扁 != null)
this.挨扁(this, e);
}
//3.觸發事件
public void 被扁()
{
Console.WriteLine("被扁ing...");
this.挨扁了(EventArgs.Empty);
}
}
class 我
{
private 小弟 我小弟 = null;
public 我(小弟 小小弟)
{
this.我小弟 = 小小弟;
//註冊事件
this.我小弟.挨扁 += new EventHandler(this.担心);
}
public void 担心(object sender, EventArgs e)
{
Console.WriteLine("我担心");
}
}
class InstanceDelegate
{
[STAThread]
public static void Main ()
{
小弟 小弟弟 = new 小弟();
我 大哥 = new 我(小弟弟);
小弟弟.被扁();
Console.ReadLine();
} //end of main
}
}
- Events Sample Code(1)
- Events Sample Code(2)
- sample code
- Dojo widgets introduction and sample code (1)
- JDK 1.5 Sample Code
- logic font sample code
- MetaWeblogAPI C# Code Sample
- JavaScript Sample Code
- XMl - xerces code sample
- java concurrent code sample
- Sample CRC Code
- sample code of webview
- Spring AOP Sample Code
- sample transaction code
- File Output sample code
- Thread sample code
- MKMapView Sample Code
- !!!C++ sample code
- 我终于相信了人有幻觉
- oracle create database
- 使用wise for windows installer 5.0 打包mysql数据库
- Spring MVC framework深入分析之一--总体分析
- Spring MVC framework深入分析二--ApplicationContext之谜
- Events Sample Code(1)
- spring事务探索
- Events Sample Code(2)
- Hibernate/Spring/Struts架构使用OpenSessionInView的问题
- 利用windows脚本实现文件的自动备份
- 在那鲜花盛开的地方
- 马克思主义哲学的基本概念
- 安裝SVN Server 和 Eclipse SVN Plugin
- 李开复的Blog