我正在通过TCP(TcpClient)与一台仪器进行异步通信. 有大量但数量有限的响应(被转换为字符串)可以从仪器返回,我不希望有大量的IF-THEN-ELSE语句.如何创建一个SortedList,其中的值指向成员函数?
我试过以下几种方法
private SortedList<string, object> functionList = new SortedList<string, object>();
private void InitializeList()
{
functionList.Add("Time", ProcessTime(string)); // Invalid expression term 'string'
functionList.Add("Date", ProcessTime()); // There is no argument given that corresponds
// to the required formal parameter 'reply' of
// 'ProcessTime(string)'
}
private void ProcessTime(string reply)
{
// More complex processing here, but you should get the idea.
Console.WriteLine(reply);
}
我肯定以前有人问过这个问题,但我找不到在哪里.