Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从未调用的If语句_C#_Html Agility Pack - Fatal编程技术网

C# 从未调用的If语句

C# 从未调用的If语句,c#,html-agility-pack,C#,Html Agility Pack,我有这段代码 Category featured = new Category() { active = true, Categories = new Category[0], description = "", identifier = "featured", name = "Featured",

我有这段代码

Category featured = new Category()
            {
                active = true,
                Categories = new Category[0],
                description = "",
                identifier = "featured",
                name = "Featured",
                Products = new Product[0],
                url = siteUrl,
            };
StatisticCounters.CategoriesCounter();
下面是我的代码

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

            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功能子类别(HtmlNode标准、类别类别、特色类别)
{
列表类别=新列表();
{
如果(category.name==“特色”)
{

var nodes=std.SelectNodes(//span[contains(@class,'widget')][position()最好签入调试器。有时,空格会导致问题。这是许多程序员犯的一个简单错误。当我们从数据库获取数据时,可能会有一些前导空格。当我们与某个值比较时(认为没有前导空格),如果不修剪这些空格,它将无法进行比较

string s1 = "TEST"; 
string s2 = " TEST"; 
if (s1 == s2) { 
    Console.WriteLine("Equal"); 
}

请使用trim函数删除所有空白并进行比较。

在此处放置一个断点,然后查看
类别的值是多少?为什么您认为它从未被调用?我的建议是删除类别列表声明下面的手镯。它们对我来说没有任何意义,因为您正在以分号。如果我是诚实的,我不知道为什么它没有被调用。我能想到的唯一一件事是它没有类别特征=新类别()。但是我不确定如何让它找到它。它将被调用,但评估结果似乎是错误的。您向我们展示了变量
featured
是如何填充的,但您正在检查
category.name
而不是
featured.name
。因此
category.name
很可能与
featured不同“
if
语句的主体将被跳过。