473,396 Members | 1,865 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,396 software developers and data experts.

Was events keyword necessary?

Hi,

I find that when i define a delegate, it gets derived from
MulticastDelegate, which provides all funtionality that events would provide
(like registering new handlers etc.). Then, apart from being a bit more
neater, could there have been any other reason that an 'event' keyword became
necessary in C#?

Thanks in advance,
--
Rakesh Rajan
Nov 16 '05 #1
7 1949
I believe that the reason for the keyword is just semantics, although there are some benefits. Designers group events together to
allow for quick "registration" of handlers at design time. Also, events do not have to be constructed as delegates require use of
the "new" keyword.

Visit the C# programmers reference on MSDN for more info:

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

and more specifically

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

--
Dave Sexton
ds*************@somethingdigitalBYE-SPAM.com (remove BYE-SPAM)
[Please do not reply by email unless asked to]
-----------------------------------------------------------------------
"Rakesh Rajan" <Ra*********@discussions.microsoft.com> wrote in message news:6F**********************************@microsof t.com...
Hi,

I find that when i define a delegate, it gets derived from
MulticastDelegate, which provides all funtionality that events would provide
(like registering new handlers etc.). Then, apart from being a bit more
neater, could there have been any other reason that an 'event' keyword became
necessary in C#?

Thanks in advance,
--
Rakesh Rajan

Nov 16 '05 #2
hi,

Delegate is somewhat same and more powerful than our old C++ functional
pointer.

Suppose if you want to cal that function through any event then you have to
go for custom event. and the keywrod event is must.
Nov 16 '05 #3
Yes...I think initialization with the new operator is the only major benefit...

"Dave" wrote:
I believe that the reason for the keyword is just semantics, although there are some benefits. Designers group events together to
allow for quick "registration" of handlers at design time. Also, events do not have to be constructed as delegates require use of
the "new" keyword.

Visit the C# programmers reference on MSDN for more info:

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

and more specifically

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

--
Dave Sexton
ds*************@somethingdigitalBYE-SPAM.com (remove BYE-SPAM)
[Please do not reply by email unless asked to]
-----------------------------------------------------------------------
"Rakesh Rajan" <Ra*********@discussions.microsoft.com> wrote in message news:6F**********************************@microsof t.com...
Hi,

I find that when i define a delegate, it gets derived from
MulticastDelegate, which provides all funtionality that events would provide
(like registering new handlers etc.). Then, apart from being a bit more
neater, could there have been any other reason that an 'event' keyword became
necessary in C#?

Thanks in advance,
--
Rakesh Rajan


Nov 16 '05 #4

"Rakesh Rajan" <Ra*********@discussions.microsoft.com> wrote in message
news:4F**********************************@microsof t.com...
Yes...I think initialization with the new operator is the only major
benefit...
Its not quite that. Events and delegates are semantically different beasts.
An event provides an abstraction of the concept of an subscribable event, it
strictly allows you to subscribe and unsubscribe(add and remove), it does
not allow invocation or other delegate operations.

When you use a delegate, anyone can raise that event and anyone can clear
the delegate list at its whim. An event, on the other hand, only
allows(generally) access to add and remove functionality, thus you cannot
remove random delegates or randomly invoke delegates as you would be able to
with a literal delegate field.


"Dave" wrote:
I believe that the reason for the keyword is just semantics, although
there are some benefits. Designers group events together to
allow for quick "registration" of handlers at design time. Also, events
do not have to be constructed as delegates require use of
the "new" keyword.

Visit the C# programmers reference on MSDN for more info:

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

and more specifically

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

--
Dave Sexton
ds*************@somethingdigitalBYE-SPAM.com (remove BYE-SPAM)
[Please do not reply by email unless asked to]
-----------------------------------------------------------------------
"Rakesh Rajan" <Ra*********@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
> Hi,
>
> I find that when i define a delegate, it gets derived from
> MulticastDelegate, which provides all funtionality that events would
> provide
> (like registering new handlers etc.). Then, apart from being a bit more
> neater, could there have been any other reason that an 'event' keyword
> became
> necessary in C#?
>
> Thanks in advance,
> --
> Rakesh Rajan


Nov 16 '05 #5
Rakesh Rajan <Ra*********@discussions.microsoft.com> wrote:
I find that when i define a delegate, it gets derived from
MulticastDelegate, which provides all funtionality that events would
provide (like registering new handlers etc.). Then, apart from being
a bit more neater, could there have been any other reason that an
'event' keyword became necessary in C#?


See http://www.pobox.com/~skeet/csharp/faq/#event.delegate

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6
I agree with Daniel's description of the semantical differences between the events keyword and delegates declared as fields.

He has explained why the events keword was "necessary".

--
Dave Sexton
ds*************@somethingdigitalBYE-SPAM.com (remove BYE-SPAM)
[Please do not reply by email unless asked to]
-----------------------------------------------------------------------
"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in message news:uO**************@tk2msftngp13.phx.gbl...

"Rakesh Rajan" <Ra*********@discussions.microsoft.com> wrote in message
news:4F**********************************@microsof t.com...
Yes...I think initialization with the new operator is the only major
benefit...


Its not quite that. Events and delegates are semantically different beasts.
An event provides an abstraction of the concept of an subscribable event, it
strictly allows you to subscribe and unsubscribe(add and remove), it does
not allow invocation or other delegate operations.

When you use a delegate, anyone can raise that event and anyone can clear
the delegate list at its whim. An event, on the other hand, only
allows(generally) access to add and remove functionality, thus you cannot
remove random delegates or randomly invoke delegates as you would be able to
with a literal delegate field.


"Dave" wrote:
I believe that the reason for the keyword is just semantics, although
there are some benefits. Designers group events together to
allow for quick "registration" of handlers at design time. Also, events
do not have to be constructed as delegates require use of
the "new" keyword.

Visit the C# programmers reference on MSDN for more info:

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

and more specifically

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

--
Dave Sexton
ds*************@somethingdigitalBYE-SPAM.com (remove BYE-SPAM)
[Please do not reply by email unless asked to]
-----------------------------------------------------------------------
"Rakesh Rajan" <Ra*********@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
> Hi,
>
> I find that when i define a delegate, it gets derived from
> MulticastDelegate, which provides all funtionality that events would
> provide
> (like registering new handlers etc.). Then, apart from being a bit more
> neater, could there have been any other reason that an 'event' keyword
> became
> necessary in C#?
>
> Thanks in advance,
> --
> Rakesh Rajan


Nov 16 '05 #7
Clear as crystal...thanks all :)

"Dave" wrote:
I agree with Daniel's description of the semantical differences between the events keyword and delegates declared as fields.

He has explained why the events keword was "necessary".

--
Dave Sexton
ds*************@somethingdigitalBYE-SPAM.com (remove BYE-SPAM)
[Please do not reply by email unless asked to]
-----------------------------------------------------------------------
"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in message news:uO**************@tk2msftngp13.phx.gbl...

"Rakesh Rajan" <Ra*********@discussions.microsoft.com> wrote in message
news:4F**********************************@microsof t.com...
Yes...I think initialization with the new operator is the only major
benefit...


Its not quite that. Events and delegates are semantically different beasts.
An event provides an abstraction of the concept of an subscribable event, it
strictly allows you to subscribe and unsubscribe(add and remove), it does
not allow invocation or other delegate operations.

When you use a delegate, anyone can raise that event and anyone can clear
the delegate list at its whim. An event, on the other hand, only
allows(generally) access to add and remove functionality, thus you cannot
remove random delegates or randomly invoke delegates as you would be able to
with a literal delegate field.


"Dave" wrote:

> I believe that the reason for the keyword is just semantics, although
> there are some benefits. Designers group events together to
> allow for quick "registration" of handlers at design time. Also, events
> do not have to be constructed as delegates require use of
> the "new" keyword.
>
> Visit the C# programmers reference on MSDN for more info:
>
> http://msdn.microsoft.com/library/de...sReference.asp
>
> and more specifically
>
> http://msdn.microsoft.com/library/de...lrfeventpg.asp
>
> --
> Dave Sexton
> ds*************@somethingdigitalBYE-SPAM.com (remove BYE-SPAM)
> [Please do not reply by email unless asked to]
> -----------------------------------------------------------------------
> "Rakesh Rajan" <Ra*********@discussions.microsoft.com> wrote in message
> news:6F**********************************@microsof t.com...
> > Hi,
> >
> > I find that when i define a delegate, it gets derived from
> > MulticastDelegate, which provides all funtionality that events would
> > provide
> > (like registering new handlers etc.). Then, apart from being a bit more
> > neater, could there have been any other reason that an 'event' keyword
> > became
> > necessary in C#?
> >
> > Thanks in advance,
> > --
> > Rakesh Rajan
>
>
>



Nov 16 '05 #8

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

Similar topics

14
by: JPRoot | last post by:
Hi I use the following syntax to have events inherited from base to child classes which works nicely (virtual and override keyword on events). But I am wondering if it is a "supported" way of using...
8
by: JPRoot | last post by:
Hi M. Jeffrey Tan, Just hopping you didn't forget me? :) Thanks JPRoot ----- \"Jeffrey Tan\" wrote: -----
4
by: LP | last post by:
Hello! I am still transitioning from VB.NET to C#. I undertand the basic concepts of Delegates, more so of Events and somewhat understand AsyncCallback methods. But I need some clarification on...
11
by: John Salerno | last post by:
My general problem with events seems to be that there are so many parts to them, and I'm not sure where they all go or when you use which parts. For example, there's the delegate, the event name,...
30
by: Burkhard | last post by:
Hi, I am new to C# (with long year experience in C++) and I am a bit confused by the language construct of events. What is it I can do with events that I cannot do with delegates? At the moment...
7
by: Bruce | last post by:
I have a DotNet C++ class that I would like to fire an event to then be used by VB.Net using the With Events keyword. I have experience creating connection point events for ActiveX controls, it is...
5
by: Jeremy | last post by:
Is there any good reading about pitfalls of scoping when using events? Here is my specific issue: function MyType() { this.foo = "bar"; this.textbox = document.createElement("input");...
6
by: Smithers | last post by:
Just looking to compile a list of "all the ways to implement events". I'm NOT looking to get into the merits or mechanics of each in this thread... just want to identify them all - good, bad, and...
7
by: Siegfried Heintze | last post by:
I'm studying the book "Microsoft Visual Basic.NET Language Reference" and I would like some clarify the difference between events and delegates. On page 156 I see a WinForms example of timer that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.