Note:
Public class Game
{
Public event ScoreChangeEventHandler ScoreChange;
Protected void OnScoreChange ()
{
If (ScoreChange! = Null) ScoreChange (30, ref true); // in the class, this can be used
}
Except this class, ScoreChange can only appear on the left of the operator + = and-=]
You may first encounter this system in the graphic user interface framework. A game is like a control on the user interface. It triggers events based on user input, while a referee is similar to a form that processes the event.
[Note] the delegation was first introduced by Microsoft Visual J ++ and was also designed by Anders Hejlsberg. It is also one of the reasons for Sun and Microsoft's technical and legal disputes. James Gosling, a Java designer, once made a humble and humorous comment on Anders Hejlsberg, saying that he should call him "Mr method pointer" because of his disconnections with Delphi ". After studying Sun's dispute over Delegation, I think it seems fair to call Gosling "Everything is a kind of mr." J. In the programming field over the past few years, many people have replaced the "reality is object-oriented, so we should use object-oriented abstraction to simulate it ".
The debate between Sun and Microsoft on delegation can be seen here:
Http://www.Javasoft.com/docs/white/delegates.html Http://msdn.microsoft.com/visualj/technical/articles/delegates/truth.asp]