C# event handling (compared to Java)

后端 未结 9 720
离开以前
离开以前 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:11

    Thank you all so much for your answers! Finally I'm starting to understand what is going on. Just one thing; It seems that if each event had a different number/type of arguments I'd need to create a different :: EventArgs class to deal with it:

    public void computerStarted(Computer computer);
    public void computerStopped(Computer computer);
    public void computerReset(Computer computer);
    public void breakPointHit(Computer computer, int breakpoint);
    public void computerError(Computer computer, Exception exception);
    

    This would require three classses to deal with the events!? (Well two custom, and one using the default EventArgs.Empty class)

    Cheers!

提交回复
热议问题