473,325 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Coding Practice Question - Usage of System.EventArgs

The .NET Framework provides us with built-in event handlers:
System.EventHandler
and the generic
System.EventArgs<TEventArgs>

It appears that those built-in event handler delegates are just a
convenience for us, as we can use those instead of creating a new delegate
for every event that we implement.

Question: Is it good to use those built-in event handlers as a matter of
course - and not create a new delegate for our events - provided that the
standard event handler signature [object sender, EventArgs e] will suffice?

Is there any advantage to creating a new delegate _even when_ the built-in
ones listed above would suffice?

Thanks.
Sep 4 '07 #1
4 2152
Frankie,

I don't see any. There really isn't a difference between a delegate
signature of:

delegate void MyEventHandler(object sender, MyEventArgs args);

And using EventHandler<MyEventArgs>. They will do the same thing, and
there isn't any real difference between them.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Frankie" <A@B.COMwrote in message
news:Oj**************@TK2MSFTNGP03.phx.gbl...
The .NET Framework provides us with built-in event handlers:
System.EventHandler
and the generic
System.EventArgs<TEventArgs>

It appears that those built-in event handler delegates are just a
convenience for us, as we can use those instead of creating a new delegate
for every event that we implement.

Question: Is it good to use those built-in event handlers as a matter of
course - and not create a new delegate for our events - provided that the
standard event handler signature [object sender, EventArgs e] will
suffice?

Is there any advantage to creating a new delegate _even when_ the built-in
ones listed above would suffice?

Thanks.

Sep 4 '07 #2
"Frankie" <A@B.COMwrote in message
news:Oj**************@TK2MSFTNGP03.phx.gbl...
The .NET Framework provides us with built-in event handlers:
System.EventHandler
and the generic
System.EventArgs<TEventArgs>

It appears that those built-in event handler delegates are just a
convenience for us, as we can use those instead of creating a new delegate
for every event that we implement.

Question: Is it good to use those built-in event handlers as a matter of
course - and not create a new delegate for our events - provided that the
standard event handler signature [object sender, EventArgs e] will
suffice?

Is there any advantage to creating a new delegate _even when_ the built-in
ones listed above would suffice?
In all the code I've seen, the standard practice is to use
System.EventArgs whenever it is sufficient, that is when you do not need to
pass any additional data inside the argument.

The only advantage that I can think for using a different type of
delegate is that it would leave room for future expansion, meaning that you
could write lots of code using YourEventArgs and if you needed to modify the
event in the future to include an e.something in your event arguments you
would not need to modify all the existing code (except those parts that
needed to make some use of the new fields). But I haven't seen any code that
follows this practice, so I guess that it is not frequent at all to find
yourself in this situation (having to add some data to existing eventargs).
Sep 4 '07 #3
I think the primary reason for EventHandler is that the signature is so
common throughout the .NET Framework that it makes sense to have a predefined
one. With EventArgs (which is not really an "event handler", but a separate
class) this provides the base class from which all more complex EventArgs
functionality is derived, even though in many cases it serves no purpose ,
e.g., "EventArgs.Empty"
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"Frankie" wrote:
The .NET Framework provides us with built-in event handlers:
System.EventHandler
and the generic
System.EventArgs<TEventArgs>

It appears that those built-in event handler delegates are just a
convenience for us, as we can use those instead of creating a new delegate
for every event that we implement.

Question: Is it good to use those built-in event handlers as a matter of
course - and not create a new delegate for our events - provided that the
standard event handler signature [object sender, EventArgs e] will suffice?

Is there any advantage to creating a new delegate _even when_ the built-in
ones listed above would suffice?

Thanks.
Sep 5 '07 #4
RE: << EventArgs (which is not really an "event handler>>

geeze! I meant to put System.EventHandler in the subject of the OP..... not
EventArgs... hopefully the actual question I posed there made it clear what
I was inquiring about....



"Peter Bromberg [C# MVP]" <pb*******@yahoo.yohohhoandabottleofrum.comwrote
in message news:EC**********************************@microsof t.com...
>I think the primary reason for EventHandler is that the signature is so
common throughout the .NET Framework that it makes sense to have a
predefined
one. With EventArgs (which is not really an "event handler", but a
separate
class) this provides the base class from which all more complex EventArgs
functionality is derived, even though in many cases it serves no purpose ,
e.g., "EventArgs.Empty"
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"Frankie" wrote:
>The .NET Framework provides us with built-in event handlers:
System.EventHandler
and the generic
System.EventArgs<TEventArgs>

It appears that those built-in event handler delegates are just a
convenience for us, as we can use those instead of creating a new
delegate
for every event that we implement.

Question: Is it good to use those built-in event handlers as a matter of
course - and not create a new delegate for our events - provided that the
standard event handler signature [object sender, EventArgs e] will
suffice?

Is there any advantage to creating a new delegate _even when_ the
built-in
ones listed above would suffice?

Thanks.

Sep 5 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: george young | last post by:
I had developed the habit of using the neat python form: if someinstance: someinstance.memb() because it seems cleaner than "if someinstance is not None". {please no flames about "is not None"...
1
by: Xah Lee | last post by:
Dear functional programing comrades, Among the community of automatons of the IT industry, there is a popular quote about "theory vs practice" that goes something along the lines of "in theory...
144
by: Natt Serrasalmus | last post by:
After years of operating without any coding standards whatsoever, the company that I recently started working for has decided that it might be a good idea to have some. I'm involved in this...
39
by: Patrick | last post by:
The c# code style guide that I follow suggests that class variables (fields) be coded with camel casing, like this: int recordId; string name; It also suggests that variables within methods...
3
by: ct-86 | last post by:
http://www.cdbook.cn/book.asp?id=2393 Organizational and Policy Issues 1 0. Don't sweat the small stuff. (Or: Know what not to standardize.) 2 1. Compile cleanly at high warning levels. 4 2....
1
by: Melanie Peterson | last post by:
Hi all, I'm coding for an event in a DataGrid. I started with OnPreRender, but at this point I don't really care which event I use, as long as my code executes before the DataGrid displays on...
7
by: Robert Seacord | last post by:
The CERT/CC has just deployed a new web site dedicated to developing secure coding standards for the C programming language, C++, and eventually other programming language. We have already...
4
by: gentsquash | last post by:
On some of my course pages, I quote (with attribution) small sections of Wikipedia and the like. E.g, the top of http://en.wiktionary.org/wiki/entropy has "entropia" in Greek font, ...
1
by: murthychvrm | last post by:
why we declare "ReportDocument doc;" in this coding?what it is doing here? using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.