How events are assigned in .NET
Posted
by Matt
on Stack Overflow
See other posts from Stack Overflow
or by Matt
Published on 2010-06-03T19:33:08Z
Indexed on
2010/06/03
19:34 UTC
Read the original article
Hit count: 313
I just realized I didn't fully understand why in .NET you assign events using a += symbol.
I figured this out yesterday when I needed to remove an event and without thinking I was doing
someobject.onsomeevent += null
thinking that would just remove the event I had previously assigned.
After some investigation, I figured out I had to
someobject.onsomeevent -= someeventmethod;
After figuring this out, I realized I don't understand how event methods are assigned in .NET.
So I have a few questions:
First, does it mean that I can do
someobject.onsomeevent += someeventmethod;
someobject.onsomeevent += someeventothermethod;
If so, when onsomeevent occurs will they both get hit, and in the order specified or simultaneously?
Furthermore, how can I determine what event methods are already assigned to someobject.onsomeevent?
Second, is there a way to save the events methods in some class, remove them from someobject.onsomeevent and re-assign them after some other procedures that would normally trigger the event are complete?
© Stack Overflow or respective owner