User Event in C#

by - 7:16 AM

Very simple user event in C#. Codes are:

using System;
using System.Collections.Generic;
using System.Text;

namespace Events
{
class Program
{
static void Main(string[] args)
{
EventTestClass obj = new EventTestClass();
obj.RaiseEvent1 += new EventTestClass.TestEventDelegate(obj_RaiseEvent);
obj.Run("call 1", "arg");
obj.Run("call 2", "arg");
obj.Run("call 3", "arg");
Console.ReadLine();

}

static void obj_RaiseEvent(object sender, object Args)
{
Console.WriteLine("Done. "+sender.ToString()+"...............\n");
}

}
class EventTestClass
{
public delegate void TestEventDelegate(object sender, object Args);
public event TestEventDelegate RaiseEvent1;
public EventTestClass()
{

}

public void Run(object sender, object Args)
{
Console.WriteLine("Run called");
RaiseEvent1(sender, Args);
}

}

}

You May Also Like

0 comments