C# 并非所有代码路径都使用html agility pack返回值

C# 并非所有代码路径都使用html agility pack返回值,c#,html-agility-pack,C#,Html Agility Pack,我对c#和html敏捷包相当陌生,我编写了这段代码来解析网页 private IList<Category> GetFeatureSubCategories(HtmlNode std, Category category) { List<Category> categories = new List<Category>(); { if (category.name == "Featured")

我对c#和html敏捷包相当陌生,我编写了这段代码来解析网页

private IList<Category> GetFeatureSubCategories(HtmlNode std, Category category)
    {
        List<Category> categories = new List<Category>();
        {
            if (category.name == "Featured")
            {
                var nodes = std.SelectNodes("//span[contains(@class,'widget')] [position() <= 4]");

                foreach (var node in nodes)
                {
                    string name = SiteParserUtilities.ParserUtilities.CleanText(System.Net.WebUtility.HtmlDecode(node.InnerText));
                    string url = node.Attributes["href"].Value;
                    string identifier = url.Split('/').Last().Replace(".html", "");
                    WriteQueue.write(string.Format(" Category [{0}].. {1} ", name, url));

                    IList<Category> sub = GetSubCategories(std);
                    Category c = new Category()
                    {
                        active = true,
                        Categories = sub.ToArray(),
                        description = "",
                        identifier = identifier,
                        name = name,
                        Products = new Product[0],
                        url = url,
                    };
                    StatisticCounters.CategoriesCounter();
                    categories.Add(c);
                }


            }

        }

    }
私有IList GetFeatureSubCategories(HtmlNode标准,类别)
{
列表类别=新列表();
{
如果(category.name==“特色”)
{

var nodes=std.SelectNodes(//span[contains(@class,'widget')][position()假设您的方法返回类型为
IList
的对象,您的代码中没有
return
语句。您可能希望从方法返回
categories
,您可以将return语句放在方法结束之前

private IList<Category> GetFeatureSubCategories(HtmlNode std, Category category)
{
        List<Category> categories = new List<Category>();
        {
        //.................
return categories;
}
私有IList GetFeatureSubCategories(HtmlNode标准,类别)
{
列表类别=新列表();
{
//.................
退货类别;
}

假设您的方法返回类型为
IList
的对象,您的代码中的任何地方都没有
return
语句。您可能希望从方法返回
categories
,您可以将return语句放在方法结束之前

private IList<Category> GetFeatureSubCategories(HtmlNode std, Category category)
{
        List<Category> categories = new List<Category>();
        {
        //.................
return categories;
}
私有IList GetFeatureSubCategories(HtmlNode标准,类别)
{
列表类别=新列表();
{
//.................
退货类别;
}

错误是不言自明的:您的代码不会返回任何东西,而方法的签名保证它会返回任何东西


返回类别;
在方法的末尾就可以了。

错误是不言自明的:您的代码没有
返回任何东西,而方法的签名保证它会返回


返回类别;
在方法末尾即可。

您没有从声明返回ILIst的方法返回任何内容


添加
返回类别;
在最后一个“}”括号后

您没有从声明返回ILIst的方法返回任何内容


添加
返回类别;
在倒数第二个“}”括号后

您的方法重新运行
IList
,但您没有在代码中的任何位置返回
IList
。调用:-

return categories;

您的方法重新运行一个
IList
,但您不会在代码中的任何地方返回一个
IList
。调用:-

return categories;

您不能在代码中的任何位置重复类别

在代码末尾添加return语句,就像我添加的一样

private IList<Category> GetFeatureSubCategories(HtmlNode std, Category category)
{
    List<Category> categories = new List<Category>();
    {
        if (category.name == "Featured")
        {
            var nodes = std.SelectNodes("//span[contains(@class,'widget')] [position() <= 4]");

            foreach (var node in nodes)
            {
                string name = SiteParserUtilities.ParserUtilities.CleanText(System.Net.WebUtility.HtmlDecode(node.InnerText));
                string url = node.Attributes["href"].Value;
                string identifier = url.Split('/').Last().Replace(".html", "");
                WriteQueue.write(string.Format(" Category [{0}].. {1} ", name, url));

                IList<Category> sub = GetSubCategories(std);
                Category c = new Category()
                {
                    active = true,
                    Categories = sub.ToArray(),
                    description = "",
                    identifier = identifier,
                    name = name,
                    Products = new Product[0],
                    url = url,
                };
                StatisticCounters.CategoriesCounter();
                categories.Add(c);
            }
        }
    }
         return categories;
}
私有IList GetFeatureSubCategories(HtmlNode标准,类别)
{
列表类别=新列表();
{
如果(category.name==“特色”)
{

var nodes=std.SelectNodes(//span[contains(@class,'widget')][position()您没有在代码中的任何位置返回类别

在代码末尾添加return语句,就像我添加的一样

private IList<Category> GetFeatureSubCategories(HtmlNode std, Category category)
{
    List<Category> categories = new List<Category>();
    {
        if (category.name == "Featured")
        {
            var nodes = std.SelectNodes("//span[contains(@class,'widget')] [position() <= 4]");

            foreach (var node in nodes)
            {
                string name = SiteParserUtilities.ParserUtilities.CleanText(System.Net.WebUtility.HtmlDecode(node.InnerText));
                string url = node.Attributes["href"].Value;
                string identifier = url.Split('/').Last().Replace(".html", "");
                WriteQueue.write(string.Format(" Category [{0}].. {1} ", name, url));

                IList<Category> sub = GetSubCategories(std);
                Category c = new Category()
                {
                    active = true,
                    Categories = sub.ToArray(),
                    description = "",
                    identifier = identifier,
                    name = name,
                    Products = new Product[0],
                    url = url,
                };
                StatisticCounters.CategoriesCounter();
                categories.Add(c);
            }
        }
    }
         return categories;
}
私有IList GetFeatureSubCategories(HtmlNode标准,类别)
{
列表类别=新列表();
{
如果(category.name==“特色”)
{

var nodes=std.SelectNodes(//span[contains(@class,'widget')][position()方法承诺在此处返回一个
IList

private IList<Category> GetFeatureSubCategories
:

具有非void返回类型的方法必须使用该返回 关键字返回一个值


该方法承诺在此处返回一个
IList

private IList<Category> GetFeatureSubCategories
:

具有非void返回类型的方法必须使用该返回 关键字返回一个值


您没有返回代码中任何位置的类别可能重复的您没有返回代码中任何位置的类别可能重复的