2 add new tags
| link
source | link

Was including a keyword for events a mistake in C#?

C# has events built in with a keyword. So if you want to declare an event, you write:

public event MyEventHandler SomethingHappened;

It is convenient, as it does allow you to add multiple event handlers, although it also prevents you from customising how events are handled, such as if you want to ensure that certain event handlers would always run in a certain order.

It seems that code would be more flexible if it was instead written as:

public Event<MyEventHandler> SomethingHappened = default;

Then you could also substitute in custom events. I also see no reason why the += operation couldn't still be used for adding new handlers. So does this simply decrease flexibility or does the keyword offer anything else?