C # event experience (1)

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.