| | |
Differences between Delegates and Events
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2004
Posts: 1,655
Reputation:
Solved Threads: 35
They aren't the same. An event is an event. A "delegate" assigns a particular event handler to an object instance. Thus, when an object event happens, the proper procedure/method is called.
An example might help. I frequently code things so that a single method is called for all instances of a class. No matter which button is clicked, call my generic "button_click" method. That method will use the event arguments to determine which button was actually clicked.
In order to assign all button click events to a single method, I have to code the delegates.
An example might help. I frequently code things so that a single method is called for all instances of a class. No matter which button is clicked, call my generic "button_click" method. That method will use the event arguments to determine which button was actually clicked.
In order to assign all button click events to a single method, I have to code the delegates.
•
•
Join Date: Sep 2005
Posts: 5
Reputation:
Solved Threads: 0
* Event is Arraylist of delegates .
* Delegate ( as its English meaning ) : Secretary or someone who connect two persons throuh him .
* Delegate can fire only one method
But Event fire more than one delegate , each call one method
* Example : in Windows App. or ASP.NET App.
Button : is a class that has internally an event called ( eg. click ) and there is
a method you want to do if this button clicked so make an instance of the delegate
which button.click deal with ( System.EventHandler ) and make this delegate
execute the method eg. Button1_Click
Code :
in initializer of The Form Class :
Button1.Click += new System.EventHandler(this.button1_Click) ;
And make amethod :
private void button1_Click(object sender, System.EventArgs e)
{
// write your own code
}
* Delegate ( as its English meaning ) : Secretary or someone who connect two persons throuh him .
* Delegate can fire only one method
But Event fire more than one delegate , each call one method
* Example : in Windows App. or ASP.NET App.
Button : is a class that has internally an event called ( eg. click ) and there is
a method you want to do if this button clicked so make an instance of the delegate
which button.click deal with ( System.EventHandler ) and make this delegate
execute the method eg. Button1_Click
Code :
in initializer of The Form Class :
Button1.Click += new System.EventHandler(this.button1_Click) ;
And make amethod :
private void button1_Click(object sender, System.EventArgs e)
{
// write your own code
}
![]() |
Similar Threads
- Good Book for beginners in C# (C#)
- Custom UserControls Throwing Events Up the Hierarchy (C#)
- ComboBox Events (VB.NET)
- Delegate (C#)
- Key Events (Java)
Other Threads in the C# Forum
- Previous Thread: Quick directory question
- Next Thread: New Thread is not allowing proper Paint Events
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# check checkbox client code color combobox control conversion csharp custom database datagrid datagridview dataset datastructure datetime degrees development draganddrop drawing encryption enum event excel file files form format forms function gdi+ grade hash httpwebrequest image index input install java label lisp list listbox listener mandelbrot math mouseclick mp3 mysql operator path photoshop picturebox pixelinversion post programming radians regex remote remoting richtextbox safari serialization server sleep snooze socket sql statistics stream string table tables tcp text textbox thread time timer update usercontrol usercontrols validation visualstudio webbrowser windows winforms wpf xml






