+ =与活动运营 [英] += operator with Events

查看:85
本文介绍了+ =与活动运营的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public void Bar()
{
    Foo foo = new Foo();
    **foo.MyEvent += foo_MyEvent;**
    foo.FireEvent();        
}

void foo_MyEvent(object sender, EventArgs e)
{
    ((Foo)sender).MyEvent -= foo_MyEvent;
}



嘿,我有点不熟悉的事件,可能有人告诉我是什么+ =运算符的事件呢?

Hey I'm a bit unfamiliar with events, could someone tell me what the += operator does with events?

推荐答案

+ = 订阅的事件。上的 + = 将被添加到该事件跟踪的内部列表右手侧委托或方法,并且当所属类触发该事件,列表中的所有与会代表将被调用。

+= subscribes to an event. The delegate or method on the right-hand side of the += will be added to an internal list that the event keeps track of, and when the owning class fires that event, all the delegates in the list will be called.

这篇关于+ =与活动运营的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆