The book is either in error or out of context...
(almost?) all of the event handler delegates in the FCL use this signature,
but it is not a requirement -- rather it is a guideline.
public delegate void SomeEventHandler( object sender,
MyClassThatInheritsFromEventArgs e);
....
public event SomeEventHandler SomeEvent;
This is the preferred pattern for events. However, it's not required. Just
as valid would be
public delegate int SomeEventHandler( int x, int y);
....
public event SomeEventHandler SomeEvent;
Now, ignoring statndards and best practices is done at your own risk, but
there's no technical reason you can't do the last one.
The nice thing about using the first example is that if someone didn't care
for the extended information in the second parameter, they could use
System.EventHandler delegates and hook up to your events blindly. But
again, not a requirement, just a strong guideline.
"news.microsoft.com" <ea******@hotmail.com> wrote in message
news:uC**************@TK2MSFTNGP12.phx.gbl...
In one of my books called "Mastering C#" there is a statement that reads
"All event handler delegates must return void and accept two parameters.
The first parameter is an object, and it represents the object that raises the
event... The second is a parameter that is an object of a class derived
from the System.EventArgs class".
Now I know that this can not be true in general because I have created
events that do not match these parameters. I know there are some system
delegates that are designed to be used with event handers that are defined
with this signiture and using one of those would require the appropriate
parameters to be passed to it.
I just though maybe I was missing something and thought if anyone can
clarify things, that would be great!.
Thanks for your help
Earl