c# - 错误 : Not all code paths return a value

标签 c# function methods dictionary error-handling

我写了下面的代码来计算一个 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/

相关文章:

java - Singleton 类中的非静态成员

c# - 如何在 C# .NETMF 4.0 中捕获未处理的异常?

c# - 解析自定义日期时间格式

c# - 团结 : Create a texture from Terrain

javascript - 为什么从函数调用分配给属性innerHTML不起作用?

methods - 抽象方法未指定主体 - 尝试实现 super 接口(interface)方法的接口(interface)在 JDK 8 中给出编译时错误

c# - 从 C# 中的非托管 C++ DLL 获取字节数组上的指针

C函数参数可以设置变量吗?

r - 将列表作为函数参数传递 R

java - 返回方法找不到符号