singrdk/base/Windows/csic/test/event.cs

26 lines
503 B
C#
Raw Permalink Normal View History

2008-11-17 18:29:00 -05:00
using System;
public delegate void E(object sender, string msg);
class T {
public event E x;
public static event E y;
public void fire(string s) {
x("x", s);
y("y", s);
}
public void F(E handler) {
x += handler;
y += handler;
}
}
class U {
static public void handler(object sender, string msg) {
Console.WriteLine("{0}: {1}", sender, msg);
}
static public void Main() {
T t = new T();
t.x += new E(handler);
t.F(new E(handler));
t.fire("fire!");
}
}