I'm wondering why the EventArgs
constructor isn't protected as it seems like waste (although tiny) to allocate resources for an empty object for every event, especially when there is a singleton EventArgs.Empty
that's clearly more efficient to use. This surprises me, especially when other parts of the .NET do have a protected/private constructor to avoid multiple, unnecessary allocations, e.g. Comparer<T>
.
Are there any cases where creating a new EventArgs()
(not a subclass) actually makes sense, or is the constructor merely available to ease the usage for non-experienced developers?
I would say that its because the EventArgs
class has the ComVisible
attribute set to true
.
This is supported by the following FxCop rule:
A reference type that is specifically marked as visible to COM contains a public parameterized constructor but does not contain a public default (parameterless) constructor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With