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

delegates and events

I am writing a costum delegate and I wondere what is the difference
between an event and a delegate instance? Why should I declare an
event with the event keyword instead of declaring it as an instance of
the corresponding delegate?

Mar 25 '07 #1
4 1475
>I am writing a costum delegate and I wondere what is the difference
between an event and a delegate instance? Why should I declare an
event with the event keyword instead of declaring it as an instance of
the corresponding delegate?
An event doesn't give direct access to the underlying delegate. It
simply provides a way for the consumer to add and remove handlers.

The difference is somewhat similar to using a property vs a public
field.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Mar 25 '07 #2
Personally, I think there r 2 difference:

1) using event keyword,'+=' operator will bound as many motheds as you want
to the delegate by managing a inner list;
2:) you can see different icon when you type you code in vs.net.

"dani kotlar" <da*********@gmail.com>
??????:11**********************@y80g2000hsf.google groups.com...
>I am writing a costum delegate and I wondere what is the difference
between an event and a delegate instance? Why should I declare an
event with the event keyword instead of declaring it as an instance of
the corresponding delegate?


Mar 26 '07 #3
gshzheng <gs******@gmail.comwrote:
Personally, I think there r 2 difference:

1) using event keyword,'+=' operator will bound as many motheds as you want
to the delegate by managing a inner list;
2:) you can see different icon when you type you code in vs.net.
Those are just visible differences in simple situations - the real
differences are much more profound.

See http://pobox.com/~skeet/csharp/events.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 26 '07 #4
Thank you , Jon

I have misunderstanded both event keword and delegate.
That artical teaches me a lot.

I really appreciate your kind help.
gshzheng
20070326
"Jon Skeet [C# MVP]" <sk***@pobox.com>
??????:MP************************@msnews.microsoft .com...
gshzheng <gs******@gmail.comwrote:
>Personally, I think there r 2 difference:

1) using event keyword,'+=' operator will bound as many motheds as you
want
to the delegate by managing a inner list;
2:) you can see different icon when you type you code in vs.net.

Those are just visible differences in simple situations - the real
differences are much more profound.

See http://pobox.com/~skeet/csharp/events.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Mar 26 '07 #5

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

Similar topics

4
by: Marty McDonald | last post by:
It is still unclear to me why we would use events when delegates seem to do just fine. People say that events make it so the publisher doesn't need to know about the listeners. What does that...
0
by: Steven Brown | last post by:
I'm trying to figure out how to safely use .NET events/delegates in a thread-safe class. There are a couple problems. One is that the standard "if(EventName != null) EventName(...);" call can...
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...
3
by: Chris | last post by:
Hi, what is the difference between using events and delegates (apart from the syntax) ? have a look at following (working) programs please (you can just copy/paste and build it) : First...
4
by: Tim | last post by:
There are a set of clients who need to be notified of certain events. I have used events and delegates (publisher-Subscriber model) for the notification mechanism. All the clients register with...
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...
2
by: kristian.freed | last post by:
Hi, I currently work in a project written fully in C# where we make extensive use of delegates and events. We have a model where a "state", an object holding data but not much code but which...
5
by: raylopez99 | last post by:
I understand delegates (static and non-static) and I agree they are very useful, and that the "Forms" used in the Windows .NET API could not work without them. That said, I'm curious as to how...
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...
9
by: raylopez99 | last post by:
Hello all— I’m trying to get the below to work and cannot get the format right. It’s from this example: http://msdn.microsoft.com/en-us/library/8627sbea(VS.71).aspx What it is: I’m trying...
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
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...
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: 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: 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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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.