Answered by:
Delegates and Events

Question
-
User1396641445 posted
Hi, What is the difference b/w Delegates and Events. I have little bit confusion. Where delegates are used, and when we have to used delegates. Can, you give some examples(both delebates and events) in vb.net.
Thanks!
Thursday, February 11, 2010 5:45 AM
Answers
-
User-1659704165 posted
Hi,
There No keyword Delegate While using event
Event can decalred in Inteface But delegate is Not.
event is Class specific and delegate can used who ever can Acess it..
OR
http://blog.monstuff.com/archives/000040.html
chk the abov elink
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, February 11, 2010 7:27 AM -
User-952121411 posted
Check out some of the following links with detailed descriptions and examples in VB.NET:
Visual Basic Language Concepts - Events and Delegates:
http://msdn.microsoft.com/en-us/library/aa903294(VS.71).aspx
VB.NET School - Delegates and Events:
http://www.programmersheaven.com/2/Les_VBNET_10_p1
Event Handling in VB.NET:
http://devcity.net/Articles/25/1/20020316.aspx
Hope this helps!
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, February 11, 2010 10:24 AM -
User406085191 posted
Hi delegates and events with example
http://www.codersource.net/csharp_delegates_events.html
http://www.codeproject.com/KB/cs/delegates-part1.aspx
http://msdn.microsoft.com/en-us/library/aa288459(VS.71).aspx
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, February 16, 2010 4:54 AM -
User2115139740 posted
this link might help you
http://www.vikramlakhotia.com/Difference_between_delegate_and_event.aspx
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, February 16, 2010 4:58 AM -
User-379429695 posted
For a dummy explination, as I would be one who requires such an answer:
(this is more "in concept" that exact code syntax, but I will do my best with the syntax as well)
a delegate is a reference to a method. in other words, you could have a function, but instead of having to call the function by its name every time you want to use it, you could assign that function to an object, or... a variable.
Delegate Function MyDelegate(ByVal p As Integer, ByVal q As Integer) As Integer Public Sub TestSomething() Dim arithMethod As New MyDelegate(AddressOf Add) Dim res As Integer = arithMethod(3, 4) Console.WriteLine("The result of your operation is: " & res) End Sub Function Add(ByVal a As Integer, ByVal b As Integer) As Integer Return a + b End Function
An event on the other hand, is something that your program (or possibly even the .net platform) does, or can do.. that you have the ability to be notified about. such as the value of a dropdown list changing, it has an event "selected value changed".
hopefully i didnt just make a bigger mess, and this helps clear things up :)
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, February 16, 2010 9:05 AM
All replies
-
User-1659704165 posted
Hi,
There No keyword Delegate While using event
Event can decalred in Inteface But delegate is Not.
event is Class specific and delegate can used who ever can Acess it..
OR
http://blog.monstuff.com/archives/000040.html
chk the abov elink
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, February 11, 2010 7:27 AM -
User-952121411 posted
Check out some of the following links with detailed descriptions and examples in VB.NET:
Visual Basic Language Concepts - Events and Delegates:
http://msdn.microsoft.com/en-us/library/aa903294(VS.71).aspx
VB.NET School - Delegates and Events:
http://www.programmersheaven.com/2/Les_VBNET_10_p1
Event Handling in VB.NET:
http://devcity.net/Articles/25/1/20020316.aspx
Hope this helps!
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, February 11, 2010 10:24 AM -
User1364706731 posted
Events are the actions of the system on user manipulations (e.g. mouse clicks, key press, timer etc.) or any event triggered by the program.
Delegate is type which holds the method(s) reference in an object. It is also refered as a type safe function pointers.Monday, February 15, 2010 5:15 AM -
User406085191 posted
Hi delegates and events with example
http://www.codersource.net/csharp_delegates_events.html
http://www.codeproject.com/KB/cs/delegates-part1.aspx
http://msdn.microsoft.com/en-us/library/aa288459(VS.71).aspx
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, February 16, 2010 4:54 AM -
User2115139740 posted
this link might help you
http://www.vikramlakhotia.com/Difference_between_delegate_and_event.aspx
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, February 16, 2010 4:58 AM -
User-379429695 posted
For a dummy explination, as I would be one who requires such an answer:
(this is more "in concept" that exact code syntax, but I will do my best with the syntax as well)
a delegate is a reference to a method. in other words, you could have a function, but instead of having to call the function by its name every time you want to use it, you could assign that function to an object, or... a variable.
Delegate Function MyDelegate(ByVal p As Integer, ByVal q As Integer) As Integer Public Sub TestSomething() Dim arithMethod As New MyDelegate(AddressOf Add) Dim res As Integer = arithMethod(3, 4) Console.WriteLine("The result of your operation is: " & res) End Sub Function Add(ByVal a As Integer, ByVal b As Integer) As Integer Return a + b End Function
An event on the other hand, is something that your program (or possibly even the .net platform) does, or can do.. that you have the ability to be notified about. such as the value of a dropdown list changing, it has an event "selected value changed".
hopefully i didnt just make a bigger mess, and this helps clear things up :)
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, February 16, 2010 9:05 AM