delegate void WorkProgressing();
delegate int WorkCompleted();
class Worker {
public void DoWork() {
Console
if( started != null ) started();
Console
if( progressing != null ) progressing();
Console
if( completed != null ) {
int grade = completed();
Console
}
}
public WorkStarted started;
public WorkProgressing progressing;
public WorkCompleted completed;
}
class Boss {
public int WorkCompleted() {
Console
return
}
}
class Universe {
static void Main() {
Worker peter = new Worker();
Boss boss = new Boss();
peter
peter
Console
Console
}
} 靜態監聽者
這樣
static void WorkerStartedWork() {
Console
}
static int WorkerCompletedWork() {
Console
return
}
static void Main() {
Worker peter = new Worker();
Boss boss = new Boss();
peter
peter
peter
peter
Console
Console
}
}
[
From:http://tw.wingwit.com/Article/program/net/201311/15529.html