You can declare an event in a class as follows:
Class
{
Public event eventhandler testevent; // here: the event name is generally capitalized and defined by a delegate. The keyword event is added before the delegate.
Protected virtual void ontestevent (eventargs E)
{
If (this. testevent! = NULL)
{
This. testevent (this, e); // here: the event function is triggered by Delegation
}
}
}
Today, I am surprised to find that if I reference A in another class as follows:
Class B
{
A;
Public B ()
{
This. A = new ();
}
Void test ()
{
A. testevent (this, new eventargs (); // here: an error is returned. This is not to say that the following is a symptom. (Symptom 1)
}
}
Regarding symptom 1,
This indicates that the event model in C # is by default. Only when an event class is created can the event be directly triggered, but not externally. Does this indicate
What are the differences between events and delegated instances?
In addition, the relationship between the event and the message mechanism cannot be judged because it is blocked by the Net Framework encapsulation.
Mysterious: you need to know about Win32 API and hook. If you get to Net Framework 3.0, the new winfx doesn't know if
There are some changes in this regard, such as making messages more operational.