我有一個Dictionary<int, int> idsAndTypes = new Dictionary<int, int>();
和我有一個使用的字典LINQ查詢和列表
List<Product> products = new List<Product>()
的產品清單,產品類被如下
class Product
{
public int Id {get;set;}
public int Type{get;set;}
}
字典idsAndTypes包含的ID和類型,現在我想在列表上使用linq查詢來更新基於詞典中的id的產品類型.... 我知道另一種方式可以如下:
foreach (int item in idsAndTypes.Keys)
{
Product.Where(product => product.Id == item).
Select(product => product).ToList()[0].
Type = idsAndTypes[item];
}
但我想用linq查詢來做到這一點,以避免foreach
循環,有沒有辦法做到這一點? 請建議...
非常感謝您先生回答... – 2009-10-16 05:40:04