static void Main(string[] args) { Console.WriteLine("please input selection for char or string"); string inputString = Console.ReadLine(); Console.WriteLine("please input {0}", inputString); UserInputMonitor monitor_char = new UserInputMonitor(); UserStrInputMonitor monitor_string = new UserStrInputMonitor(); Client client_char = new Client(monitor_char); Client client_string = new Client(monitor_string); if (inputString == "char") { monitor_char.Run(); } else if (inputString == "string") { monitor_string.Run(); } }
public Client(UserStrInputMonitor m) { m.OnUserStrRequest += new UserStrInputMonitor.UserStrRequest(this.ShowMessage); //m.OnUserRequest+=new m.UserRequest(this.ShowMessage); //注意这种写法是错误的,因为委托是静态的 }