Hi,
I have been playing around trying to get an understanding of delegates and events -
I would like to know if there is any difference between how the following 2 lines of code function
ie:
public delegate void NotifyFrm1(Object sender, ValueUpdatedEventArgs e); public static event NotifyFrm1 NotifyFrm1Action;
as compared to:
public delegate void NotifyFrm1(Object sender, ValueUpdatedEventArgs e); public static NotifyFrm1 NotifyFrm1Action;
I get exactly the same results by ommitting the word event.
thanks
-Barb

Delegates and events
WidgetWorking
events are used to implement the obvserver pattern. you (especially w/ a static event) can have any number of subscribers of that event. one subscriber could do:
staticEvent = null;
and guess what he'd cut every other subscribed class out of the notification loop.
events only allow for addition or removal of a single event handler to / from the event. you are not allowed to set the event directly equal to the handler, which enforces the obvserver pattern.
they both do the same thing (which is invoke a callback), but the "event" will enforce the rule that nobody kills the notifications outside of the scope of their knowledge. think of an event as a notification and a delegate as a direct callback, even though they do the same thing.
I hope that makes sense.
h3nry
Well one of them is not an event, the other one is.
The "public static NotifyFrm1 NotifyFrm1Action" is just a property which you can access (get and set values).
The other one "public static EVENT.." is an event declaration, which means that you can create events and raise events to the subscribers of that event.
Events are multicast, meaning when you have X number of subscribers and you raise an event, it is heard to all the subscribers and they act upon it.
http://msdn.microsoft.com/library/default.asp url=/library/en-us/csref/html/vcwlkeventstutorial.asp
hope this helps, its a tutorial about events.
http://www.c-sharpcorner.com/Code/2003/Nov/EventsinNet.asp
http://www.codeproject.com/csharp/EventDrivenModel.asp
http://www.eggheadcafe.com/articles/20040429.asp
http://www.csharphelp.com/archives/archive253.html
xplosiv_1
well it depends what you want to do, what exactly are you doing What is your code
Events are needed or at least the declaration if you want to create an event.
As said, many classes can subscribe to say an event and when the event is raised, all classes that have subscribed to it will be notified of the event being fired.
You cannot do this with just a method in a single class, which means you have to reference a class with this method in other classes which is bad practice and inefficient just to call that method.
As said, the statement without "event" is just making that line a simple object variable in the class, which means classes can access that object.
SMaia
Okay, I have read through all of the above links, and went thru all of the examples. For every example, I took out the word "event" in the event declaration and the example still functioned exactly as before. To me it seems uneccessary to spell it out as an event. I have not been able to find one single example where it is necessary to call it an event. If anyone could provide me with one, it would be greatly appreciated.
thanks
-Barb
amendez
ok thanks,
guess I need to do some more research - thanks for the link
-Barb
J Beaulieu - CS Product Team
Thanks for the replies
I think that is what I was looking for - I don't have any specific code that I am trying to do, I was just trying to get an understanding.
So my understanding now is that an event is kind of a more restrictive delegate instance.
If this is the case, then I am satisfied.
thanks so very much
gfe
Simply, thing is that,
The only two operations that can be performed on a delegate instance that is exposed from an object as Event
are += and -=, when this is exposed as raw delegate, any one can perform any operation on it and even some one can invoke the methods associated with the delegate.