发一个接口做参数的例子
回头接口
using System; using System.Collections.Generic; using System.Text; namespace observer2 { public interface IMaster { void buy_slave(ISlave some_slave); void send_command(); } public interface ISlave { void slave_do_work(); } class Test { static void Main(string[] args) { master master2=new master(); slave slave2=new slave(); master2.buy_slave(slave2); master2.send_command(); } } public class master:IMaster { public delegate void some_function(); public event some_function some_event; public void buy_slave(ISlave some_slave) { some_event += some_slave.slave_do_work; } public void send_command() { Console.WriteLine("master:where is my slave?"); some_event(); } } public class slave:ISlave { public void slave_do_work() { Console.WriteLine("slave:I am here,my lord!"); } } }