What's the difference between delegate,event and method? [closed]
(analogy wo开发者_JAVA百科uld be very helpful). The answer so far on this topic either lacking the three subjects or are not clear enough for me.
Method = a function in a class.
Delegate = a pointer to a Method.
Event = a delegate with special restrictions - it can only be invoked by the class that declares it
Method - a function with some logic.
Delegate - a function pointer. You can think of it as a variable which can reference methods.
Event - a collection of delegates, which you can execute/invoke at will.
A method is a member function.
A delegate is an object that can hold a member-function.
An event is, well, an event. With each event there is one associated delegate. All the methods that are held in the delegate are called when the event is fired
加载中,请稍侯......
精彩评论