日期:2014-05-17 浏览次数:20418 次
int Count = 0;
Dictionary<int, Order> dic = new Dictionary<int, Order>();
List<Product> ProductList = new List<Product>
{
new Product
{
ShopID = 1,
Name = "商品一"
},
new Product
{
ShopID = 2,
Name = "商品二"
},
new Product
{
ShopID = 1,
Name = "商品三"
},
new Product
{
ShopID = 2,
Name = "商品四"
},
new Product
{
ShopID = 3,
Name = "商品五"
}
};
Order CurOrder = null;
foreach (var Product in ProductList)
{
dic.TryGetValue(Product.ShopID, out CurOrder);
if (CurOrder == null)
{
CurOrder = new Order { ID = ++Count };
dic.Add(Product.ShopID, CurOrder);