using System; using System.Collections.Generic; using System.Text; namespace 委托练习 { class Program { static String s = ""; static void Main(string[] args) { EventLooker chevic = new EventLooker(); chevic.disp+=new StringHandler(display); chevic.exit+=new StringHandler(exit); Console.Write("please input a sentence:"); while (true) { s = Console.ReadLine(); chevic.Input(s); } } static void display() { Console.WriteLine("你输入了:" + s); } static void exit() { Console.WriteLine("It's no way to exit"); } } public delegate void StringHandler(); class EventLooker { public event StringHandler disp; public event StringHandler exit; public void Input(String s) { if (s != "") { disp(); } if (s.Equals("exit")) { exit(); } } } }