我写了下面的代码来计算一个 XML 文件的节点数:
private Dictionary<string, int> ExtractNodeInfo(string fileContent)
{
XmlDocument xmlDocument;
xmlDocument = new XmlDocument();
xmlDocument.Load(fileContent);
var ediNodes = xmlDocument.DocumentElement.SelectNodes("/EDI");
Dictionary<string, int> nodeCount = new Dictionary<string, int>();
foreach (XmlNode nodes in ediNodes)
{
FileManager.nodeRecurse(nodes, nodeCount);
}
foreach (var entry in nodeCount)
{
Console.WriteLine(entry.ToString());
}
}
但它给了我以下错误:'XmlFileManager.FileManager.ExtractNodeInfo(string)': not all code paths return a value.
最佳答案
您没有返回值。
你需要在你的方法结束时有一个 return 语句,在这种情况下:
return nodeCount;
关于c# - 错误 : Not all code paths return a value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9980292/