delegate和event.docx

  1. 1、本文档共3页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
delegate和event

delegate)和事件(event)文章来源网络 属于事件分类 电脑编程网整理 2007830简介:这是c#:代表(delegate)和事件(event)的详细页面,介绍了和事件,有关的知识,加入收藏请按键盘ctrl+D,谢谢大家的观看!要查看更多有关信息,请点击此处? 代表(delegate):?它是c#语言里面的函数指针,代表可以指向某一个函数,在运行的时候调用这个函数的实现。下面来看看它的实现步骤:声明一个delegate对象。实现和delegate具有相同参数和返回值的函数实现(可以是静态和非静态的)。产生一个delegate对象的时候,把你刚刚实现的函数作为参数传给他的构造函数。请看下面例子:? using?system;using?system.collections.generic;using?system.text;namespace?usingdelegate...{????public?delegate?void?mydelegate(string?mydelegate);//声明一个delegate对象和?c#:代表(delegate)和事件(event)?有关的c#、asp.net、c++编程小帖士:strongCLng(expression)转换表达式为Long 型态。????public?class?testclass????...{??//实现有相同参数和返回值的函数??public?void?hellodelegate(string?mydelegate)??...{console.writeline(mydelegate);??}?//实现有相同参数和返回值的静态函数??public?static?void?hellostaticdelegate(string?mystaticdelegate)??...{console.writeline(mystaticdelegate);??}????}????class?program????...{??static?void?main(string[]?args)??...{testclass?testclass?=?new?testclass();mydelegate?mydelegate?=?new?mydelegate(testclass.hellodelegate);//产生delegate对象mydelegate(hello?delegate);//调用mydelegate?mystaticdelegate?=?new?mydelegate(testclass.hellostaticdelegate);//产生delegate对象mystaticdelegate(hello?static?delegate);//调用??}????}}事件(event):让我通过一个例子来模拟事件的整个过程:创建一个button类,它里面有一个click 事件。创建一个form类,他里面有一个我们上面定义的button类。要求:当我们用户单击button类的时候from类要对他进行处理,输出一条信息“我知道你被单击了” 首先我们会单击button,然后button会通知form,然后from就作出相应。这个过程在c#里面应该怎么做到呢?下面我会列出上述例子的源代码(这里就不介绍怎么声明event等等内容了):using?system;using?system.collections.generic;using?system.text;namespace?usingevent...{????public?delegate?void?clickeventhandler(object?sender,?eventargs?e);//声明一个代表:请看文章最后面note????public?class?mybutton??//创建mybottom????...{??public?event?clickeventhandler?clickevent;//声明一个事件??public?void?click()???//单击mybutton??...{if?(clickevent?!=?null)...{????console.writeline(mybutton:?我被单击了);????clickevent(this,?null);??//抛出事件,给所有相应者}??}????}????public?class?myform????...{??public?mybutton?mybutton?=?new?mybutton();??public?myform()??...{//添加事件到mybutton中,当mybutton被单击的时候就会调用相应的处理函数mybutto

文档评论(0)

asd522513656 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档