我想在我的方法中返回一个OrderedDictionary,但是我的代码出错......
我不知道为什么我不能这样做:
public OrderedDictionary getAllPortsInformations()
{
OrderedDictionary SerialPort = filtreXml("/catalog/cd/SerialPort", "SerialPort");
OrderedDictionary BaudRate = filtreXml("/catalog/cd/BaudRate", "BaudRate");
OrderedDictionary DataBits = filtreXml("/catalog/cd/DataBits", "DataBits");
OrderedDictionary StopBits = filtreXml("/catalog/cd/StopBits", "StopBits");
OrderedDictionary ParityBits = filtreXml("/catalog/cd/ParityBits", "ParityBits");
OrderedDictionary ReadTimeout = filtreXml("/catalog/cd/ReadTimeout", "ReadTimeout");
OrderedDictionary WriteTimeout = filtreXml("/catalog/cd/WriteTimeout", "WriteTimeout");
OrderedDictionary PinCode = filtreXml("/catalog/cd/PinCode", "PinCode");
OrderedDictionary output = new OrderedDictionary();
foreach (DictionaryEntry sp in SerialPort)
output.Add(sp.Key, sp.Value);
foreach (DictionaryEntry br in BaudRate)
output.Add(br.Key, br.Value);
foreach (DictionaryEntry db in DataBits)
output.Add(db.Key, db.Value);
foreach (DictionaryEntry sb in StopBits)
output.Add(sb.Key, sb.Value);
foreach (DictionaryEntry pb in ParityBits)
output.Add(pb.Key, pb.Value);
foreach (DictionaryEntry rt in ReadTimeout)
output.Add(rt.Key, rt.Value);
foreach (DictionaryEntry wt in WriteTimeout)
output.Add(wt.Key, wt.Value);
foreach (DictionaryEntry pc in PinCode)
output.Add(pc.Key, pc.Value);
return output;
}
错误:错误1'application.Xml.getAllPortsInformations()':所有代码路径不一定返回值
答案 0 :(得分:6)
您的上一个foreach
循环在范围内没有任何内容。要么摆脱它,要么
foreach (DictionaryEntry pc in PinCode) { }
答案 1 :(得分:0)
你的最后一个foreach什么都没做?或者这是一个错字。