C#移除所有事件绑定的方法
作者:青水 时间:2023-07-25 11:00:52
本文实例讲述了C#移除所有事件绑定的方法。分享给大家供大家参考。具体分析如下:
private delegate int DEL_TEST_EventHandler(int m, int n);
private event DEL_TEST_EventHandler DelTestEventHandler;
/// <summary>
/// 移除所有的事件绑定
/// </summary>
/// <param name="clearEvent"></param>
private void clear_event(DEL_TEST_EventHandler clearEvent)
{
Delegate[] dels = DelTestEventHandler.GetInvocationList();
foreach (Delegate d in dels)
{
//得到方法名
object delObj = d.GetType().GetProperty("Method").GetValue(d, null);
string funcName = (string)delObj.GetType().GetProperty("Name").GetValue(delObj, null);
Debug.Print(funcName);
DelTestEventHandler -= d as DEL_TEST_EventHandler;
}
}
//测试主函数
private void test()
{
DelTestEventHandler += add;
DelTestEventHandler += sub;
DelTestEventHandler += add;
DelTestEventHandler += sub;
clear_event(DelTestEventHandler);
}
private int add(int m, int n)
{
return m + n;
}
private static int sub(int m, int n)
{
return m - n;
}
希望本文所述对大家的C#程序设计有所帮助。
标签:C#,移除,事件,绑定
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
SpringBoot 开发提速神器 Lombok+MybatisPlus+SwaggerUI
2022-07-08 07:40:23
![](https://img.aspxhome.com/file/2023/6/61516_0s.jpg)
Mybatis一对多查询的两种姿势(值得收藏)
2023-07-01 00:20:08
![](https://img.aspxhome.com/file/2023/9/61669_0s.png)
Java求一个分数数列的前20项之和的实现代码
2021-08-22 14:59:58
Springboot多种情况yml配置代码实例
2022-05-14 23:26:00
SpringCloud Feign实现微服务之间相互请求问题
2022-08-29 08:20:53
![](https://img.aspxhome.com/file/2023/6/119136_0s.jpg)
深入解析JVM之内存结构及字符串常量池(推荐)
2023-01-02 19:48:20
![](https://img.aspxhome.com/file/2023/9/66469_0s.png)
一步步教你写Slack的Loading动画
2023-04-27 06:56:30
![](https://img.aspxhome.com/file/2023/7/97877_0s.gif)
Java总结篇系列:Java泛型详解
2023-01-25 03:42:58
java求最大公约数与最小公倍数的方法示例
2023-01-23 03:28:58
![](https://img.aspxhome.com/file/2023/6/87366_0s.png)
C#基于HttpWebRequest实现发送HTTP请求的方法分析
2022-01-04 22:51:03
Flutter 图片开发核心技能快速掌握教程
2023-08-16 22:01:51
![](https://img.aspxhome.com/file/2023/4/108294_0s.png)
Java简单使用redis-zset实现排行榜
2021-06-07 20:34:54
浅谈MyBatis中@MapKey的妙用
2023-09-25 10:42:02
![](https://img.aspxhome.com/file/2023/7/81887_0s.png)
Android实现毛玻璃效果的对话框
2021-07-19 03:28:42
![](https://img.aspxhome.com/file/2023/8/94258_0s.png)
WinForm生成验证码图片的方法
2022-05-11 17:49:33
Android自定义有限制区域的图例角度自识别涂鸦工具类完结篇
2022-10-22 23:05:13
![](https://img.aspxhome.com/file/2023/9/138509_0s.jpg)
java反射获取和调用方法
2021-11-23 11:05:02
springBoot详解集成Swagger流程
2023-02-26 22:23:33
![](https://img.aspxhome.com/file/2023/0/89640_0s.png)
java虚拟机深入学习之内存管理机制
2023-07-03 21:15:40
![](https://img.aspxhome.com/file/2023/5/101785_0s.png)
C#无法打开计算机“.”上的 IISADMIN 服务的解决方法
2023-02-04 21:46:54
![](https://img.aspxhome.com/file/2023/4/100084_0s.png)