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.