首页 > 其他 > 详细

委托和事件-未完结

时间:2020-09-10 20:53:27      阅读:72      评论:0      收藏:0      [点我收藏+]

继承体系: 代理-->System.MulticastDelegate-->System.Delegate
作用:

  1. 对签名相同的不同函数进行抽象,对它们进行封装从而达到代码复用的目的
  2. 异步调用和回调
    如何使用:
    正常的使用可以分为三步:
  3. 定义委托 delegate int GetLengthDel(string input)
  4. 创建委托的实例并指向合适的方法 GetLengthDel del=GetLengthMethod 等于
    GetLengthDel del =new GetLengthDel(GetLengthMethod);
  5. 同步或者异步调用方法
del.Invoke("input string");//
del("input string");//和上面一行是等效的 ,而且都是同步调用
//异步调用,事实上netcore已经禁止直接写这样的异步调用了;所以对这种过时的写法这里就不再讲解了
//del.BeginInvoke

委托和事件-未完结

原文:https://www.cnblogs.com/francisXu/p/13647913.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!