C# Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public delegate void Edelegate(String str);//delegate declaration first
public class EventClass
{
// declaration of event
public event Edelegate Status;
public void TriggerEvent()
{
if (Status != null)
Status("Event is triggered");
}
}
public class EventTest
{
public static void Main()
{
EventClass ec=new EventClass();
EventTest et=new EventTest();
ec.Status +=new Edelegate(et.EventCatch);
ec.TriggerEvent();
}
public void EventCatch(String str)
{
Console.WriteLine(str);
Console.ReadKey();
}
}
Output:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public delegate void Edelegate(String str);//delegate declaration first
public class EventClass
{
// declaration of event
public event Edelegate Status;
public void TriggerEvent()
{
if (Status != null)
Status("Event is triggered");
}
}
public class EventTest
{
public static void Main()
{
EventClass ec=new EventClass();
EventTest et=new EventTest();
ec.Status +=new Edelegate(et.EventCatch);
ec.TriggerEvent();
}
public void EventCatch(String str)
{
Console.WriteLine(str);
Console.ReadKey();
}
}
Output:
No comments:
Post a Comment