You must Sign In to post a response.
  • Category: ASP.NET

    What is delegate with events

    Hai All,
    May I know simple example for delegate with events in c#
    And when and how to use delegate with events

    Thanks and Regards,
  • #759510

    Delegates holds address of one or more methods.
    These are used to hide information like class
    names and method names.
    Delegates are used to create user defined events
    on fly as we needed in our code.
    Delegates are of two types
    1.Single cast delegate
    2.Multi caste delegate

    Refer below link for writing custom events using delegates.

    Sridhar Thota.
    DNS Member.
    "Hope for the best..Prepare for the worst.."

    Sridhar Thota.
    Editor: DNS Forum.

  • #759523
    delegates are function pointers that point to the function with same signature as the delegate signature whereas an event is a variable of type delegate with event keyword before the declaration.

    When an event is raised, it raises the function registered with the event. one or more functions of same signature as the delegate can be registered to the event. For example the button click event. For more information look at the below article with a clear example:

    Miss. Jain
    Microsoft Certified Technology Specialist in .Net

  • #759534
    Delegate and Event both are completely tied together. Delegates are just like function pointers for references to functions . For Example

    namespace DelegateExample
    public delegate string FDelegate (int x);

    public class Sample
    public delegate void SDelegate (char a, char b);

    More reference refer to

  • #759612

    Delegate is a type like class but it works like a function pointer where while creating the object of the delegate we pass the method parameter to the delegate object..

    purpose of using Delegate is , for calling no of methods also it will generate one stack only instead of creating multiple stack..

    its reducing the memory allocation in stack..

    hope u understood the concept of Delegates..


  • Sign In to post your comments