になってしまった場合は、リスト
私はWebAPIの世界に自分の足を浸しています。私は同じ名前で価格が異なる製品を含むリストを持っています。私がする必要があるのは削除することですすべての商品への言及は価格の変動が生じます。
例えば、
名= "コーンフレーク" 価格= "1.99M"
名= "コーンフレーク" 価格= "1.89M"
名= "ライスクリスピー" 価格= "2.09M"
名= "コーンフレーク" 価格= " 2.09M "
いいえ最終リストに表示されます。
私は一括書かれているが、それはあまりにもすぐに製品を削除していると私はそれらを削除する必要があります私は確信しています。
public IEnumerable<Product> GetProductsByCategory(int Id)
{
List<Product> sourceProductList = products.Where(p => p.CategoryID == Id).ToList();
List<Product> tempProducts = new List<Product>();
List<Product> targetProductList = new List<Product>();
foreach (var product in sourceProductList)
{
bool isInTempList = tempProducts.Any(x => x.Name == product.Name);
if (!isInTempList)
{
tempProducts.Add(product);
}
else
{
Product tempProduct = product;
bool isPriceDifferent = tempProducts.Where(y => y.Name == tempProduct.Name).Any(y => y.Price != tempProduct.Price);
if (isPriceDifferent)
{
tempProducts.RemoveAll(p => p.Name == product.Name);
// too soon as I may have lots of products with the same name
// but need to remove based on product.Name
}
}
}
targetProductList.AddRange(tempProducts);
return targetProductList;
}
ご協力いただければ幸いです。
注:他の穀物が用意されてい
@MarkByers私は決して起こらないことが保証されてきました。 – Brett