Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

event EventHandler vs EventHandler

In C# Is there a fundamental difference between using

event EventHandler<myeventargs> and EventHandler<myeventargs> As they both produce the same effect from what I can see apart from using the event keyword gives you a different icon in intellisense.

like image 287
Trey Avatar asked Aug 19 '14 10:08

Trey


People also ask

What is the difference between event and EventHandler?

In programming, an event handler is a callback routine that operates asynchronously once an event takes place. It dictates the action that follows the event. The programmer writes a code for this action to take place. An event is an action that takes place when a user interacts with a program.

What is the difference between event handlers and event listeners?

Note: Event handlers are sometimes called event listeners — they are pretty much interchangeable for our purposes, although strictly speaking, they work together. The listener listens out for the event happening, and the handler is the code that is run in response to it happening.

What is JavaFX EventHandler?

The following article provides an outline for JavaFX EventHandler. In JavaFX, Event Handling is a process which controls an event as well as decides what has to be triggered, when an event occurs. This will be done writing a code called as an event handler that executes when an event occurs.


1 Answers

They seems to be alike, but really different.

With event keyword, you are making them something like properties, which means you can register them in public, while maintain a private back-end.

However, without event keyword, it's just a public delegate field, and anyone can remove or modify others' events, which is a "encapsulation disaster" as @Jonskeet said.

Check this article by Jon Skeet, it's very helpful :)

Edit:

What I summarized above was not my original thinking, all credits to @Jonskeet's post.

like image 58
nevets Avatar answered Sep 24 '22 02:09

nevets