Reader Level:
ARTICLE

How do I Implement Custom Event Handling in C#

Posted by Ashish Singhal Articles | How do I October 27, 2005
In this article, we are going to show, how we can call custom event on our designed conditions.
  • 0
  • 0
  • 20275

Tne following source code shows how to implement custom event handling in C#.

using System;
class CustomEventBinding
{
public CustomEventBinding()
{
CustomEventHandling.operationEvent +=
new OperationEventHandler(ShowStatus);
SendNumber();
}
private void SendNumber()
{
CustomEventHandling customEventHandle =
new CustomEventHandling();
customEventHandle.CheckNumber(8);
customEventHandle.CheckNumber(9);
}
private void ShowStatus(string message)
{
Console.WriteLine(message);
}
}
class CustomEventHandling
{
public delegate void OpeartionEventHandler(string message);
public static event OperationEventHandler operationEvent;
int i = 0;
//Indicate whether given number is even or odd
public void CheckNumber(int number)
{
int rem = number % 2;
if(rem == 0)
operationEvent("Even Number");
else
operationEvent("Odd Number");
}
}

COMMENT USING

Trending up