How do static events compare to non-static events in C#?

后端 未结 5 675
误落风尘
误落风尘 2020-12-31 05:47

I just realized static events exist - and I\'m curious how people use them. I wonder how the relative comparison holds up to static vs. instance methods. For instance, a s

5条回答
  •  再見小時候
    2020-12-31 06:23

    Much of OOP can be thought of in terms of message passing.

    A method call is a message from the caller to the callee (carrying the parameters) and a message back with the return value.

    An event is a message from the source to the subscriber. There are thus potentially two instances involved, the one sending the message and the one receiving it.

    With a static event, there is no sending instance (just a type, which may or may not be a class). There still can be a recipient instance encoded as the target of the delegate.

提交回复
热议问题