惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
爱范儿
爱范儿
T
The Exploit Database - CXSecurity.com
量子位
T
Tailwind CSS Blog
T
Threatpost
The GitHub Blog
The GitHub Blog
AWS News Blog
AWS News Blog
云风的 BLOG
云风的 BLOG
K
Kaspersky official blog
P
Proofpoint News Feed
博客园 - 司徒正美
L
LangChain Blog
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 叶小钗
S
Secure Thoughts
The Last Watchdog
The Last Watchdog
Spread Privacy
Spread Privacy
H
Hacker News: Front Page
T
Troy Hunt's Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
W
WeLiveSecurity
A
Arctic Wolf
Apple Machine Learning Research
Apple Machine Learning Research
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
P
Proofpoint News Feed
T
Tor Project blog
T
The Blog of Author Tim Ferriss
I
Intezer
P
Privacy & Cybersecurity Law Blog
美团技术团队
N
Netflix TechBlog - Medium
博客园_首页
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost
Application and Cybersecurity Blog
Application and Cybersecurity Blog
G
Google Developers Blog
Attack and Defense Labs
Attack and Defense Labs
T
Tenable Blog
月光博客
月光博客
Stack Overflow Blog
Stack Overflow Blog
J
Java Code Geeks
腾讯CDC
Microsoft Security Blog
Microsoft Security Blog
A
About on SuperTechFans
Last Week in AI
Last Week in AI

博客园 - 露雨城市.NET2.0和Sql Server 2005开发研究

关于asp.net将动态页直接生成静态页的随笔(乱码) 我的神龙卡KTV点播软件只有一个遗憾了 关于清除Sql Server Express版本的数据库日志文件 关于微软2008技术预览大会南京站和Vista 也许是转折-放弃了5,6K的月薪 关于vs2005中ajax控件暴露模板中控件,请高手进来聊聊. - 露雨城市.NET2.0和Sql Server 2005开发研究 这个基础题,你能做对吗? 好久没有来发文章了,今天来秀一下。 Visual C#中父窗口和子窗口之间实现控件互操作 关于如何在子窗口中选择后,在父窗口赋值并让输入框设为只读。 - 露雨城市.NET2.0和Sql Server 2005开发研究 我的新资源网站开张了,韩国模版,韩国设计资源等。 关于在插入的模版中如何为已绑定了Text属性的TextBox设置默认值 今天好高兴,通过了微软的Sql Server 2005的70-31的考试。 赠送一张微软免费考试券 关于GridView中选择当前行的问题。 VS2005中的一个小BUG:关于Dropdownlist无法Datadinding的解决方法。 如何动态设置全局theme,及在web.config中读取pages节点的内容。 讲故事谈.NET委托:一个C#睡前故事 关于的MasterPage和Theme的问题。
在.NET2.0中如何更简单的使用委托将方法加载到事件中去
露雨城市.NET2.0和Sql Server 2005开发研究 · 2006-10-22 · via 博客园 - 露雨城市.NET2.0和Sql Server 2005开发研究

我们知道在System命名空间中,.NET为我们提供了EventHandler的委托,它的原型是delegate void EventHandler(object sender,EventArgs e),(当然这是针对某些控件的普通事件来的,其他事件的事件参数EventArgs会发生改变)所以只要我们的方法符合这个委托的原型,我们就可以使用这个委托实例。如按钮的点击事件。

button1.Click += new EventHandler(Button_Click);

所以上面的Button_Click方法只要符合EventHandler的委托原型我们就可以这样来使用它,如何定义这个方法呢?
void Button_Click(object sender,EventArgs e)
{
     MessageBox.Show("我被点击了");
}
,其实这个实现起来已经很简单了,不过在.NET2.0中,也就是Visual C# 2005中,我们可以更加简单的使用委托:
button1.Click += Button_Click;
直接将方法名加载到事件中,完成了委托了隐形调用,非常的方便。

posted on 2006-10-22 08:13  露雨城市.NET2.0和Sql Server 2005开发研究  阅读(2084)  评论()    收藏  举报