473,287 Members | 1,643 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,287 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 2150
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
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...

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.