[C #] commission basis, Lambda expressions and events

.Net version of the commission is addressing method. Delegates are type-safe class that defines the return type and parameter types.

Delegate class includes not only a reference to the method can also include references to multiple methods.

lambda expressions directly related to the commission. When the argument is a delegate type, you can use a lambda expression to implement the method referenced by the delegate.

Any delegate can hit the same place custom delegate class definition. In the delegate class can be defined inside and outside.

The commission can also be defined as top-level object in the namespace.

 

Weak events:

By event can be directly linked publisher and listener. However, garbage collection problems. E.g.

If there are no direct reference to the listener, it is still a reference publisher.

The garbage collector can not empty the memory occupied by the listener, because the publisher still retains a reference trigger event for the listener.

This strong connection can be solved by a weak event patterns. That the use of WeakEventManager as an intermediary between the publisher and listener.

 WeakEventManager <T> System.Windows centrally defined in the program are not .net core.

To use the event to be a weak reference method IWeakEventListener implement the interface defined

ReceiveWeakEvent

 

Invocation.

 

Guess you like

Origin www.cnblogs.com/SignX/p/11222467.html