-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathTrigger.cs
More file actions
60 lines (55 loc) · 1.26 KB
/
Trigger.cs
File metadata and controls
60 lines (55 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
delegate bool Condition(object obj);
delegate void Action(object obj);
class Counter
{
int val = 0;
public event Condition cond;
public event Action evn;
public int Value { get { return val; } }
public void addition(int x)
{
val += x;
Checkpoint();
}
public void Clearall()
{
val = 0;
Checkpoint();
}
void Checkpoint()
{
if (cond != null && evn != null && cond(this)) evn(this);
}
}
class Test
{
static int hval = 0;
static bool CheckpointLimit(object ctr)
{
return (((Counter)ctr).Value > 100);
}
static void Alarm(object ctr)
{
Console.WriteLine("Counter Overflow");
}
static void Reset(object ctr)
{
hval = ((Counter)ctr).Value;
Console.WriteLine("hval = " + hval);
((Counter)ctr).Clearall();
}
public static void Main()
{
Counter counter = new Counter();
counter.cond += new Condition(CheckpointLimit);
counter.evn += new Action(Alarm);
counter.evn += new Action(Reset);
counter.addition(10);
counter.addition(20);
counter.addition(30);
counter.addition(40);
counter.addition(50);
Console.Read();
}
}