0

我想在我的方法中返回一个 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 ()':所有代码路径不一定都返回值

4

2 回答 2

6

您的最后一个foreach循环在范围内没有任何内容。要么摆脱它,要么

foreach (DictionaryEntry pc in PinCode) { }
于 2013-07-10T19:02:15.373 回答
0

你最后的 foreach 什么都没做?或者这是一个错字。

于 2013-07-10T19:02:24.827 回答