如何查找 ItemID 在列表或数组中是否具有不同的 ItemCode?
How to Find If ItemID have a different ItemCode in a list or array?
我在这里需要的是我想知道那个 ItemId 是否有不同的 ItemCode,因为在我的项目中只有一个 ItemId 可以有一个 ItemCode 但位置可以尽可能不同。
有什么办法可以解决这个问题吗?
这是我的代码:
Product[] products = {
new Product { ItemId= , 1001="apple", ItemCode=9, Location=store1 },
new Product { ItemId= , 1001="apple", ItemCode=10, Location=store2 },
new Product { ItemId= , 1002="apple", ItemCode=11, Location=store3 },
new Product { ItemId= , 1002="apple", ItemCode=11, Location=store3 }
};
收集物品及其有效期:
var itemsValidity =
products.GroupBy(p => p.ItemId).
Select(g => new
{
ItemId = g.Key,
IsValid = !g.GroupBy(item => item.ItemCode).Skip(1).Any()
});
将return一组具有 ItemId 的对象和一个指示 ItemId 是否关联到多个 ItemCode 的标志。
我在这里需要的是我想知道那个 ItemId 是否有不同的 ItemCode,因为在我的项目中只有一个 ItemId 可以有一个 ItemCode 但位置可以尽可能不同。 有什么办法可以解决这个问题吗?
这是我的代码:
Product[] products = {
new Product { ItemId= , 1001="apple", ItemCode=9, Location=store1 },
new Product { ItemId= , 1001="apple", ItemCode=10, Location=store2 },
new Product { ItemId= , 1002="apple", ItemCode=11, Location=store3 },
new Product { ItemId= , 1002="apple", ItemCode=11, Location=store3 }
};
收集物品及其有效期:
var itemsValidity =
products.GroupBy(p => p.ItemId).
Select(g => new
{
ItemId = g.Key,
IsValid = !g.GroupBy(item => item.ItemCode).Skip(1).Any()
});
将return一组具有 ItemId 的对象和一个指示 ItemId 是否关联到多个 ItemCode 的标志。