Commissioned by the use of two

C # delegate

1. To delegate to the method as a parameter method is to pass, do not want to do their own thing, there is a reference type variable to a method of reference. Reference may be changed at runtime.

All delegates are derived from the class System.Delegate

  1. The commission statement

    Public delegate return type of the delegate name (passed parameters)

(1) delegate with no parameters

 

Principal (2) with parameters

 

3. multicast delegate (Multicasting of a Delegate)

Delegate object can use the "+" operator merge. Merge two calls a delegate entrusted it merged. Only the same type of trust can be combined. "-" operator is used to remove the component from the combined delegate delegate.

With this useful feature delegate, you can create a call list of methods to be called when the delegate is invoked. This is called multicast delegate (multicasting), also known as multicasting. The following program demonstrates a multicast delegate:

 

Guess you like

Origin www.cnblogs.com/mzcode/p/11028548.html