Just finished reading Jon Skeet's article about events and delegates and got a question.
Lets say first in the code I declare an event
public event EventHandler MyEvent
Then I want to raise it in the code in a manner
if (MyEvent != null)
Myevent(this,EvtArgs.Empty);
Jon says that in fact MyEvent looks somehow like this:
private EventHandler _myEvent;
public event EventHandler MyEvent
{
add
{
lock (this)
{
_myEvent += value;
}
}
remove
{
lock (this)
{
_myEvent -= value;
}
}
}
The question is what really happens when I compare MyEvent != null
?
As I understand in fact it compares _myEvent
to null
, but I am not sure.