using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class EventTest
{
int value;
public delegate void numeven();
public event numeven ChangeNum;
protected virtual void OnNumChanged()
{
if (ChangeNum != null)
{
ChangeNum();
}
else
{
Console.WriteLine("event fired");
}
}
public EventTest(int n)
{ SetValue(n); }
public void SetValue(int n)
{
if (n%2 ==0)
{
value = n;
OnNumChanged();
}
}
}
namespace ConsoleApplication3
{
public class test
{
static void Main(string[] args)
{
EventTest e = new EventTest(8);
e.SetValue(7);
e.SetValue(11);
Console.ReadKey();
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class EventTest
{
int value;
public delegate void numeven();
public event numeven ChangeNum;
protected virtual void OnNumChanged()
{
if (ChangeNum != null)
{
ChangeNum();
}
else
{
Console.WriteLine("event fired");
}
}
public EventTest(int n)
{ SetValue(n); }
public void SetValue(int n)
{
if (n%2 ==0)
{
value = n;
OnNumChanged();
}
}
}
namespace ConsoleApplication3
{
public class test
{
static void Main(string[] args)
{
EventTest e = new EventTest(8);
e.SetValue(7);
e.SetValue(11);
Console.ReadKey();
}
}
No comments:
Post a Comment