Have events always be a non-null array #7689
Replies: 3 comments 12 replies
-
Events aren't an array, they are a multicast delegate. The design where they are |
Beta Was this translation helpful? Give feedback.
-
I'm told some developers use |
Beta Was this translation helpful? Give feedback.
-
I think the challenge here, more than anything, would be the change in semantics. A lot of code has been written in the last 25 years that depends on the semantics of events and delegates. Changing that will likely break code that depended on things working a particular way. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, events have to be declared as
event DelegateType? evt
if you enable the nullable features. Even without nullable, users had to fire the event as shown below:C# now allow this syntax, but it's still less than ideal:
But imagine this syntax:
If this were implement, the compiler would actually generate one of the above. Furthermore, events could never possibly be null. Note: for backwards compatibility, the compiler would ignore the
?
that extisting versions of C# require. This might be with a compatibility warning suggesting a change to the newer syntax.Beta Was this translation helpful? Give feedback.
All reactions