C# event handling (compared to Java)

后端 未结 9 705
离开以前
离开以前 2020-12-23 23:23

I am currently having a hardtime understanding and implementing events in C# using delagates. I am used to the Java way of doing things:

  1. Define an interface f
9条回答
  •  臣服心动
    2020-12-24 00:02

    The main difference is that in C# the events are not interface-based. Instead, the event publisher declares the delegate which you can think of as a function pointer (although not exactly the same :-)). The subscriber then implements the event prototype as a regular method and adds a new instance of the delegate to the event handler chain of the publisher. Read more about delegates and events.

    You can also read short comparison of C# vs. Java events here.

提交回复
热议问题