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.