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/