C# 比较两个列表以防止重复

C# 比较两个列表以防止重复,c#,asp.net,list,dictionary,C#,Asp.net,List,Dictionary,我在尝试比较两个列表时遇到了一些问题,如果它满足了一个要求,则将其添加到另一个列表中。代码如下: // Find list of substitute with highest stock level and replace the product prodSubstitute = prodPackBLL.getProductIDWithHighestStock(categoryName); for (int count = 0; count < prodSubstitute.Count

我在尝试比较两个列表时遇到了一些问题,如果它满足了一个要求,则将其添加到另一个列表中。代码如下:

// Find list of substitute with highest stock level and replace the product
prodSubstitute = prodPackBLL.getProductIDWithHighestStock(categoryName);

for (int count = 0; count < prodSubstitute.Count; count++)
{
    foreach (KeyValuePair<string, string> pair in tempList)
    {
        // To prevent duplication of same product and select those catories 
        // which are in current category and counting them and taking them if 
        // there are less than 1 occurrences
        if (!prodSubstitute.Any(i => i.id == pair.Key) && 
            !prodIDList.Contains(prodSubstitute[count].id) && 
            !(lstCategory.Where(x => x.Equals(categoryName))
                         .Select(x => x).Count() >= 2))
        {
            prodIDList.Add(prodSubstitute[count].id);
            lstCategory.Add(categoryName);
        }
    }
}
//找到库存水平最高的替代品列表并更换产品
prodSubstitute=prodPackBLL.GetProductId具有最高库存(categoryName);
for(int count=0;counti.id==pair.Key)和
!prodiList.Contains(prodSubstitute[count].id)和
!(lstCategory.Where(x=>x.Equals(categoryName))
.Select(x=>x.Count()>=2))
{
添加(prodSubstitute[count].id);
lstcontegory.Add(categoryName);
}
}
}
我想做的是,首先我将产品按最高库存进行分类,然后存储到prodSubstitute中。至于tempList字典,数据是我选择并添加到另一个方法中的数据。如果满足要求,则将其添加到ProdList中

我的测试数据是:对于prodSubstitute,它返回我1,5,4,2,3

至于这对钥匙,它们是1,2,3。因此,如果将if语句考虑在内,那么最终的prodidle列表应该是5和4。但它返回我空。为什么会这样

如果我把它拿走!If语句中的prodSubstitute.Any(i=>i.id==pair.Key)返回1和5。我的逻辑错了吗?它不应该添加到1中,因为它已经存在于tempList中

我试图做的是循环通过prodSubstitute,如果有任何ID与pair.Key匹配,即tempList中的ID,我不会添加到prodIDList中

提前谢谢

列表列表一;
List<string> listOne;
List<string> listTwo;

List<string> uniqueList = listOne.Concat(listTwo).Distinct().ToList(); 
清单二; List uniqueList=listOne.Concat(listwo.Distinct().ToList();
我想这是因为我使用的LINQ查询导致了这个问题?因为每当我添加它时,它总是返回null。但是有一种数据类型是ProductPacking,而对于tempList,它是Dictionary,它会收到一条错误消息:Concat包含无效的arguemtn