The difference between C # delegate and events

"Delegates are type function with the same signature (method), the event is one of the commission are applied" --- old driver from the comments section

delegate to the functions in C # objects came as a "function package" passed around and realized. Because in C # function is a second-class citizen, you can not define it in the class hierarchy, nor can it be passed as an object. Therefore platform provides a bloom function of "container" when you declare one such container, inside which you can put all the signatures and consistent when you declare a function or method.
Because every statement and create a delegate are doing repetitive work, does not meet the temperament of OOP, Microsoft provided generic delegate:
Action without reference delegate has no return value
Action <> generic delegate no return value
Func <> have generic delegate return value
Predicate <> return bool value, a parameter
public delegate typeA MyDelegate(typeB b,typeC c); MyDelegate thisDelegate = (i,j) => new typeA(); 
Equivalent to:
Func<typeB,TypeC,TypeA> thisDelegate = (i,j) => new typeA(); //前两个是参数,最后一个是返回值类型


One class member in C # event is not a type, but with the "field", "property", "method" side by side. Is understood to be a delegate type, event delegate is a field in the class. event is one way to delegate the application.
Signature event commissioned a special class or object thing happened to notify other classes or objects.
Events + =, - = operator can be used outside the class, calling the event can only be used inside the class declaration event.
 

Guess you like

Origin www.cnblogs.com/1016391912pm/p/11620960.html