C # delegation and event examples

Source: Internet
Author: User

I know a lot about Java, while C # does not need to be checked for work. C # and Java are very similar in syntax, at first, I was confused about delegation and events. I believe that most beginners have similar confusions. After comparison and learning with Java, we found that this is actually the same as Java listening and events, but it is different in expression.

The delegate + event is a typical example of the observer mode. The so-called delegate is actually the observer, which cares about an event. Once this event is triggered, the observer will act.

The following is an example recently written. I believe it can help you better understand the delegation and events.

TimeEventHandler (Main (= Clock (); MyClassEventHandler tehc = MyClassEventHandler (); clock. timeChanged + = TimeEventArgs (hour, minute ,. hour =. minute =. second = ShowTime (+ args. hour ++ args. minute ++ TimeChanged = h1 = m1 = s1 = (= h2 = m2 = s2 = (s2! === TimeEventArgs args = TimeChanged (

Reprinted from: http://ruizhinet.blog.163.com/blog/static/99213828200901110564999/

Related Article

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.