在c#中的委托数据结构中+ = /-=是什么意思? [英] What is the += / -= mean in a delegate data structure in c#?
本文介绍了在c#中的委托数据结构中+ = /-=是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有此代码:
genetic = new Genetic();
genetic.foundNewBestGroupTour += new Genetico.NewBestGroupTourEventHandler(genetico_foundNewBestGroupTour);
+ =
的作用是什么?
genetic.foundNewBestGroupTour -= new Genetico.NewBestGroupTourEventHandler(genetico_foundNewBestGroupTour);
-=
的作用是什么?
推荐答案
请阅读事件。
此上下文中 + =
运算符的调用事件添加
访问器,而-=
调用删除
访问器。通常将其称为订阅和取消订阅。
The +=
operator in this context calls the event add
accessor, while -=
calls the remove
accessor. This is usually called subscribing and unsubscribing to the event.
实现事件的通常方法是一个支持多播委托的后备字段,在这种情况下,其类型为 Genetico.NewBestGroupTourEventHandler
。提到的访问者在此多播委托字段的调用列表中添加和删除。
The usual way to implement an event is to have a backing field which holds a multicast delegate, in this case of type Genetico.NewBestGroupTourEventHandler
. The accessors mentioned add and remove from the "invocation list" of this multicast delegate field.
这篇关于在c#中的委托数据结构中+ = /-=是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文