Commissioned
Defining a delegate's syntax and definition method is similar, just a keyword more than the method delegate, we all know that the method is to parameterize the type, so-called type parameterization means that the method takes a parameter, which is a parameter of a certain type, such as int, string, etc., and the delegate is the party Method Parameterization, said that the above type of parameterization, I believe you can also guess the meaning of the method parameterization, yes, is to pass the method as a parameter to a delegate.
First look at the statement that declares the delegate:
Public deletate void MyDelegate ();
Public: Access modifier delegate: keyword void: return type mydelegate: Delegate name (): Parameter list
See the Declaration people will think about why the return value of the delegate, parameter list so I can't return a string, an int? Can I add a few parameters to the delegate? The answer is: Of course, but the definition of the delegate is relative to the method, because your delegate is ultimately to register the method, and your method has some kind of signature, so you have to give a method of how to sign a delegate, the delegate will have the same signature as the method, it is similar to you with an int Type of variable to accept a string type of value, obviously not (personal understanding) ....
* Entrusted as long as the definition is possible, we do not need to care about his implementation
Use of Delegates
There are two ways to register a delegate:
First: Assign the method directly [=] or use "+ =" to give a delegate ==> delegate name =[+=] Method name
The second: The nature of the delegate is also a class, just a special class, so we can also instantiate a delegate object through the delegate constructor to register the delegate = = "Delegate Name object name = new delegate name (method name )
C # delegates and events