If you look at the code I write, seeing a line similar to the following would be fairly common:
RaiseEvent LoadComplete(Me, New EventArgs)
Yesterday, I wouldn’t have given this a second thought, but today, the story is a bit different. A friend of mine pointed me to an interesting comment by David Kean (from Microsoft) on the MSDN Wiki indicating that the line above is actually wrong!
So, based on his comment, I should be using EventArgs.Empty instead of creating a new instance, something like this:
RaiseEvent LoadComplete(Me, EventArgs.Empty)
So using EventArgs.Empty
must be better somehow, so I decided to take a look and see if I could figure out just what the difference would be. The MSDN states that “The value of Empty is a read-only instance of EventArgs equivalent to the result of calling the EventArgs constructor” – so what’s the difference? Time for a trip into the Reflector.
The Reflector shows two constructors:
Public Sub New()
End Sub
Shared Sub New()
EventArgs.Empty = New EventArgs
End Sub
So, EventArgs.Empty
just calls New EventArgs
and returns that. Right.
Anybody see something there that I’m missing? Seems to me that the somewhat more verbose, but more clear (as to what is actually happening) syntax would be better, and no less efficient. If anybody has an opinion about why you would do one instead of the other, I’d like to hear it.