473,651 Members | 2,635 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Confussed about parameters for Events

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.EventArg s 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
Nov 15 '05 #1
4 1278
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 SomeEventHandle r( object sender,
MyClassThatInhe ritsFromEventAr gs e);
....
public event SomeEventHandle r SomeEvent;

This is the preferred pattern for events. However, it's not required. Just
as valid would be
public delegate int SomeEventHandle r( int x, int y);
....
public event SomeEventHandle r 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.EventHan dler delegates and hook up to your events blindly. But
again, not a requirement, just a strong guideline.
"news.microsoft .com" <ea******@hotma il.com> wrote in message
news:uC******** ******@TK2MSFTN GP12.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.EventArg s 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

Nov 15 '05 #2
Philip, thanks for the reply. I read the entire chapter so I don't think I
got anything out of context. Overall Mastering C# is a very good and easy to
understand book but I guess the author missed on this one. No more
confussion on my part. Thanks

Earl

"Philip Rieck" <st***@mckraken .com> wrote in message
news:Oj******** ******@TK2MSFTN GP09.phx.gbl...
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 SomeEventHandle r( object sender,
MyClassThatInhe ritsFromEventAr gs e);
...
public event SomeEventHandle r SomeEvent;

This is the preferred pattern for events. However, it's not required. Just as valid would be
public delegate int SomeEventHandle r( int x, int y);
...
public event SomeEventHandle r 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.EventHan dler delegates and hook up to your events blindly. But
again, not a requirement, just a strong guideline.
"news.microsoft .com" <ea******@hotma il.com> wrote in message
news:uC******** ******@TK2MSFTN GP12.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.EventArg s 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


Nov 15 '05 #3
Earl,
As Philip suggested it is a guideline, that is worth following.

For details on the Guideline see:

http://msdn.microsoft.com/library/de...Guidelines.asp

http://msdn.microsoft.com/library/de...Guidelines.asp

Hope this helps
Jay

"news.microsoft .com" <ea******@hotma il.com> wrote in message
news:uC******** ******@TK2MSFTN GP12.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.EventArg s 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

Nov 15 '05 #4
Jay,

I have normally used these conventions because the books I have read have
done them this way, but it is great to have the official recommedations. ..
Thanks...

Earl
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:%2******** **********@TK2M SFTNGP11.phx.gb l...
Earl,
As Philip suggested it is a guideline, that is worth following.

For details on the Guideline see:

http://msdn.microsoft.com/library/de...Guidelines.asp
http://msdn.microsoft.com/library/de...Guidelines.asp
Hope this helps
Jay

"news.microsoft .com" <ea******@hotma il.com> wrote in message
news:uC******** ******@TK2MSFTN GP12.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.EventArg s 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


Nov 15 '05 #5

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

Similar topics

5
1539
by: someone | last post by:
On page 106 of the second edition of "The C Programming Language" by K & G, two stack operations PUSH n POP are given. >> PUSH *p++ = val; >>POP val = *--p; What I know about stacks is that the top of stack (tos) pointer pts to
3
1398
by: someone | last post by:
On page 106 of the second edition of "The C Programming Language" by K & G, two stack operations PUSH n POP are given. >> PUSH *p++ = val; >>POP val = *--p; What I know about stacks is that the top of stack (tos) pointer pts to
33
2588
by: C# Learner | last post by:
Note ---- Please use a fixed-width font to view this, such as Courier New. Problem
5
4472
by: Martin Bischoff | last post by:
Hi, is it possible to modify the values of a SqlDataSource's select parameters in the code behind before the select command is executed? Example: I have an SqlDataSource with a ControlParameter <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:XYZ %>"
18
1439
by: **Developer** | last post by:
I always define events with the parameters ByVal sender As Object, ByVal e As EventArgs Even if they are not used. Seems I read someplace that's the thing to do. So I then do:
2
1282
by: surjamankhatiwora | last post by:
Can you please give me a brief difference between the vb commends like End,Unload me and Me.hide with its example each...coz while coding, i m totally confussed about these commends....
7
1827
by: Andrus | last post by:
I noticed that DataGridView CellValidated() and other event handler first parameter is object: Grid.CellValidated+=new DataGridViewCellEventHandler(Grid_CellValidated); .... void Grid_CellValidated(object sender, DataGridViewCellEventArgs e) { .....
24
55168
by: =?Utf-8?B?U3dhcHB5?= | last post by:
Can anyone suggest me to pass more parameters other than two parameter for events like the following? Event: Onbutton_click(object sender, EventArgs e)" Event handler: button.Click += new EventHandler(Onbutton_click); I want to pass more information related that event. & want to use that
0
8347
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8792
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8694
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8571
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6157
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4280
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1905
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.