开发者

What's the difference between delegate,event and method? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

(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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜