H
Harlan Messinger
I've found information on an explicit way of declaring events, similar
to the way a property is declared:
private EventHandler myEvent;
public event EventHandler MyEvent
{
add
{
lock (this)
{
myEvent += value;
}
}
remove
{
lock (this)
{
myEvent -= value;
}
}
}
Here it is explicitly stated that when handlers are added to the event,
they should be added to the delegate _myEvent, and likewise for removal.
When the event is *raised*, however, I don't understand where this tells
the application to look at _myEvent for the handler(s) to be called.
The add and remove accessors both correspond to the set accessor in a
property declaration, but there isn't anything that corresponds to the
get accessor. The code above seems similar to
private int number;
public int Number
{
set
{
number = value;
}
}
and then expecting that when the statement
int x = Number;
is executed, the application will know to get the required value from
the private field number, when I haven't included a get accessor to make
it so.
What am I missing?
to the way a property is declared:
private EventHandler myEvent;
public event EventHandler MyEvent
{
add
{
lock (this)
{
myEvent += value;
}
}
remove
{
lock (this)
{
myEvent -= value;
}
}
}
Here it is explicitly stated that when handlers are added to the event,
they should be added to the delegate _myEvent, and likewise for removal.
When the event is *raised*, however, I don't understand where this tells
the application to look at _myEvent for the handler(s) to be called.
The add and remove accessors both correspond to the set accessor in a
property declaration, but there isn't anything that corresponds to the
get accessor. The code above seems similar to
private int number;
public int Number
{
set
{
number = value;
}
}
and then expecting that when the statement
int x = Number;
is executed, the application will know to get the required value from
the private field number, when I haven't included a get accessor to make
it so.
What am I missing?