`
net_liu
  • 浏览: 234044 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

发一个接口做参数的例子

 
阅读更多

发一个接口做参数的例子

回头接口

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!");
  }
  }
 }

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics