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,
    A.L.Chellappan
  • #759510
    Hi

    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.

    www.dotnetspider.com/resources/44612-Writing-custom-Events-using-Delegates.aspx

    www.dotnetspider.com/resources/34917-Delegate-C.aspx

    www.dotnetspider.com/resources/44622-Events-Delegates-Explained-Simplified-way.aspx

    Regards.
    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:

    codeproject.com/Articles/4773/Events-and-Delegates-Simplified

    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 csharpindepth.com/Articles/chapter2/events.aspx

  • #759612
    Hi,

    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..

    Thnaks,
    Chitaranjan


  • Sign In to post your comments