方法什么都不返回

时间:2014-05-06 13:39:00

标签: c#

我真的很喜欢这个。我有一个方法应该返回一个字符串列表。

public List<string> getValueFromAttributeName(string strXMLPath, string strXMLNode, string strAttributeName, string strAttributeValue)
{
    // initialite the return list
    List<string> lstValues = new List<string>();

    // create XML object
    XmlDocument targetXML = new XmlDocument();
    // load domain config into XML object
    targetXML.Load(strXMLPath);
    // get the root node of the XML object
    XmlElement targetXMLRoot = targetXML.DocumentElement;
    // get target XML parent node
    XmlNode targetXMLElement = targetXMLRoot.SelectSingleNode(strXMLNode);
    // process each child node
    foreach (XmlNode childNode in targetXMLElement.ChildNodes)
    {
        // if the child node's specified attribute value is equal to desired value add to list
        if (childNode.Attributes[strAttributeName] != null && childNode.Attributes[strAttributeName].Value.ToLower() == strAttributeValue.ToLower())
        {
            lstValues.Add(childNode.InnerText);
        }
    }
    return lstValues;

}

调试此方法时,我将List lstValues填充一个值(“true”)。

那么,当从另一个方法调用该方法时,列表是EMPTY?!

List<string> lstSettings = new List<string>();
lstSettings = getValueFromAttributeName(strConfigFile, "/config/settings", "name", "someSetting");

0 个答案:

没有答案