none
Difference between events & Delegate RRS feed

  • Question

  • Hi All,

    What is exact difference between events & Delegate ?

    Is Events on the Top of Delegate ? How ? 

    Please help me here ?

    Monday, July 27, 2015 6:25 AM

Answers

  • Think it this way, delegates are the signature of event handlers to be chainloaded into event.

    It means that your event will only accept handler methods with matching signature.

    Monday, July 27, 2015 6:45 AM
    Answerer
  • Hi Sud,

    >>What is exact difference between events & Delegate ?

    Event allows things like the Windows Forms or ASP.NET designers to distinguish events from mere properties of delegate type, and provide appropriate support for them (specifically showing them on the Events tab of the Properties window).

    Another difference from a property of delegate type is that users can only add and remove event handlers, whereas with a property of delegate type they can set the value:

    someObj.SomeCallback = MyCallback;  // okay, replaces any existing callback
    someObj.SomeEvent = MyHandler;  // not okay, must use += instead

    The discussion here focuses on the event handling functionality of delegates. The following example shows an event and delegate declaration. Please refer to these links to understand more.

    What are the differences between delegates and events?

    https://msdn.microsoft.com/en-us/library/orm-9780596521066-01-17.aspx

    https://msdn.microsoft.com/en-us/library/17sde2xt(v=vs.90).aspx

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, July 28, 2015 9:41 AM

All replies

  • Think it this way, delegates are the signature of event handlers to be chainloaded into event.

    It means that your event will only accept handler methods with matching signature.

    Monday, July 27, 2015 6:45 AM
    Answerer
  • Hi Sud,

    >>What is exact difference between events & Delegate ?

    Event allows things like the Windows Forms or ASP.NET designers to distinguish events from mere properties of delegate type, and provide appropriate support for them (specifically showing them on the Events tab of the Properties window).

    Another difference from a property of delegate type is that users can only add and remove event handlers, whereas with a property of delegate type they can set the value:

    someObj.SomeCallback = MyCallback;  // okay, replaces any existing callback
    someObj.SomeEvent = MyHandler;  // not okay, must use += instead

    The discussion here focuses on the event handling functionality of delegates. The following example shows an event and delegate declaration. Please refer to these links to understand more.

    What are the differences between delegates and events?

    https://msdn.microsoft.com/en-us/library/orm-9780596521066-01-17.aspx

    https://msdn.microsoft.com/en-us/library/17sde2xt(v=vs.90).aspx

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, July 28, 2015 9:41 AM