473,516 Members | 2,865 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Delegates and Event

Hi all,
I am really confused about delegates and events can you ppl give me the
difference between these...

Regards,
....
Nov 15 '05 #1
3 1043
> I am really confused about delegates and events can you ppl give me
the
difference between these...


read this nice article
http://www.sellsbrothers.com/writing...=delegates.htm

Regards,
Wiktor Zychla
Nov 15 '05 #2
Delegates are the prototype of the function that will be called when an event is raised. Think
of it as a function pointer if you are familiar with C++.

Delegate -=> public delegate void MyDelegate(object sender, System.EventArgs e)

Some function -=> public void myfoo (object sender, System.EventArgs e) { ...Do something...}

instantiation of Delegate -=> MyDelegate mydel += new MyDelegate(myfoo);

You can add many functions to the instatiated delegate by using +=

You can call the delegate directly as if it were a function.
mydel (this, null);

Each function added to will be called in succession.

===================================

Events are generated based on some condition such as a button click or you have
withdrawn too much money out of your bank account.

Event -=> public event MyDelegate myevent;

Generate event -=> myevent ( this, null);

====================================

The main difference between the two is that there may be MANY instances of of MyDelegate
scattered through many difference source files.
MyDelegate mydel_1 += new MyDelegate(myfoo_1); inside class MyClass_1
MyDelegate mydel_2 += new MyDelegate(myfoo_2); inside class MyClass_2
MyDelegate mydel_3 += new MyDelegate(myfoo_3); inside class MyClass_3

If you use the call the delegate directly, you are doing just that. When you raise an event
it is received by ALL the implementations of the MyDelegate signature.

Cheers...

On Tue, 26 Aug 2003 17:25:46 +0530, "NotYetaNurd" <No*********@Matrix.com> wrote:
Hi all,
I am really confused about delegates and events can you ppl give me the
difference between these...

Regards,
...


Nov 15 '05 #3
Thanks fot the link wiktor

"Wiktor Zychla" <ie****@microsoft.com.no.spam> wrote in message
news:et**************@TK2MSFTNGP10.phx.gbl...
I am really confused about delegates and events can you ppl give me

the
difference between these...


read this nice article
http://www.sellsbrothers.com/writing...=delegates.htm

Regards,
Wiktor Zychla

Nov 15 '05 #4

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

Similar topics

5
2485
by: Ian Richardson | last post by:
I'm writing some code which does one thing when onreadystatechange occurs, e.g. handle.onreadystatechange = function() { blah(handle,other_params) }; ....but sometimes I need to add another, so it becomes: handle.onreadystatechange = function() { whatever_was_previously_defined(whatever);some_other_function(handle) };
14
1449
by: Mark Allison | last post by:
Hi, I am new to C# and want to create my own events within a console app. However I am struggling mentally with this, and have looked at the MSDN documentation but I am drawing a blank. Is there anywhere on the net that shows a very basic delegate and a very basic event? Some nice simple example code is what I'm looking for with no fluff...
4
22856
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 when to use one over another? If anyone could provide any additional info, your comments, best practices, any good articles, specific examples, etc....
1
55686
by: MuZZy | last post by:
Hi, Is there a way to remove all event handlers for a control's event? Say, i have a button and i want to remove all button.Click events for it - i don't know how many of them was hooked to the event and what are the functions hooked, but i need to make sure that i unwired all of them at once. I could unwire event handlers if i knew the...
4
1723
by: DKode | last post by:
Hello, I have a question about delegates and events I have a basic understanding of each, but in the apps I'm building I'm never needing to use these tools. I'm wondering when and where you should use these features. I am assuming that they are used in your presentation layer but perhaps I am sorely wrong. thank you
8
1745
by: Nicky Smith | last post by:
Hello, I'm reading Mike Gunderloy's Mcad Vb.net book, and I've also read the MS press Mcad book for the same topic ".. Windows based applications with VB.net" for exam 70-306. In the sections in both books that try to teach the use of delagates and events, I'm really lost, and to make matters worse, I've written a user-control that...
4
5816
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 the event publisher and subscribe for the events that they are interested in. When a certain event happens, the subscribers are notified about it. ...
11
1861
by: Snowbleach | last post by:
Hello, I am having trouble with the following console application. I am using delegates/event to make a clock raise an alarm when a certain amount of time has been reached. The following compiles, but code does nothing else then to produce an endless loop. Any help would be greatly appreciated, I'm probably overlooking something silly. ...
7
3406
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 uses the "WithEvents" and events. There is another example on page 124 that shows how to use delegates to sort an array. I don't understand the...
9
3094
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 to store multicast delegates in a hash table, and then fire the delegates one of two ways (after registering/ creating the delegates, etc).
0
7276
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...
0
7182
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...
0
7408
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. ...
1
7142
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
4773
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3267
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
1624
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
825
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
488
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...

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.