July 10, 2019 commissioned events

1.C # delegate (Delegate) C # in the delegate (the Delegate) pointers similar to C or C ++ function. Commission (Delegate) there is a method for a reference type variable references. Reference may be changed at runtime. Commission (Delegate) specifically intended for events and callback method. All commission (Delegate) are derived System.Delegate class. Declare a delegate (Delegate) method determines the proxy statement referenced by the delegate. A delegate may be directed to its method with the same label.

2. Principal Multicast (Multicasting of a Delegate) delegate object delegate is used in the Observer pattern 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.

3. delegate user-defined class, which defines the type of method. Storage is a series of address list with the same parameters and return type of the method, when the delegate is invoked, all the methods of this delegate list will be executed.

4. A delegate is a reference type, similar to the function pointers to other languages. System.MutiCastDelegate commissioned derived class, but the class also sent born System.Delegate class System.MutiCastDelegate

5.delegate is a type in C #, it is actually capable of holding a class for a method of reference. Different from other classes, delegate class can have a signature (signature), and it "can only hold its method signature matches the reference." It implements a function pointer function with C / C ++ is very similar. It allows you to pass a class A to the object of another method m of class B, class B so that the object can call this method m. But compared with function pointers, delegate many functions have the advantage of application delegates and events in the .Net Framework is very widely pointer does not have. First, the function pointer can only point to a static function, but delegate can reference both static function, but also can refer to non-static member functions. When referring to non-static member function, delegate this function not only save a reference to the entry point, but also save a call to this function reference to an instance of the class. Second, compared with the function pointer, the delegate is an object oriented, type-safe, reliable and controlled (Managed) object. In other words, runtime ensures delegate points to a valid method, you need not worry about delegate will point to an invalid address, or address cross-border.

Guess you like

Origin www.cnblogs.com/hanzhuopeng/p/11166280.html