Reader Level:
ARTICLE

How do I Implement Custom Event Handling in C#

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

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");
}
}

Ashish Singhal

Ashish has been working as a software engineer since 2002. He has written articles for C# Corner . He specializes in the implementation of client/server, database, graphics and/or Internet-based syste...

  • 214rank
  • 1M readers
COMMENT USING

Trending up