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

    Simple delegate & Event example in c#

    Topic : Using Event and delegate implement custom event.

    Code :
    -------
    Class A
    {
    delegate void MyDeleagate(int i);
    public event MyDelegate MyEvent;

    public void MethodA(double count, double Target)
    {
    for(int i=o; (count > Target) && (i > count); i++)
    {
    if( i == Target && MyEvent != null)
    MyEvent(i);
    }
    }
    }

    Class B
    {
    public static Main()
    {
    A objA = new A();
    objA.MyEvent += MethodB;

    objA.MethodA(200000, 19876);
    }

    void MethodB(int i)
    {
    Console.WriteLine("MethodB called");
    }
    }


    // When " i " value in MethodA eqaul to "19876" then MethodB will call.
  • #769547
    Hi Rajanikant,

    If you are going to provide any instruction about a topic, you can post this in more detailed info under "Resource" section.

    Regards,
    V.M. Damodharan
    "Your talent will be worthless, when you have fear and tension."


  • Sign In to post your comments