List<Goods> goodsList = new List<Goods>();
Goods good1 = new Goods();
good1.GoodsNumber = 1001;
good1.Title = "iphone4";
good1.GoodsForm = "京东";
goodsList.Add(good1);
Goods good2 = new Goods();
good2.GoodsNumber = 1002;
good2.Title = "HTC G11";
good2.GoodsForm = "京东";
goodsList.Add(good2);
Goods good3 = new Goods();
good3.GoodsNumber = 1003;
good3.Title = "三星NOTE2";
good3.GoodsForm = "天猫";
goodsList.Add(good3);
Goods good4 = new Goods();
good4.GoodsNumber = 1004;
good4.Title = "联想乐phone";
good4.GoodsForm = "天猫";
goodsList.Add(good4);
Goods good5= new Goods();
good4.GoodsNumber = 1005;
good4.Title = "小当家漫画";
good4.GoodsForm = "当当网";
goodsList.Add(good5);
怎么将goodsList拆分成三个goodsList
goodsList1包含京东的商品
goodsList2包含天猫的商品
goodsList3包含当当的商品
直接 分组一下即可。
var query=goodsList.GroupBy(g=>g.GoodsForm);
dic<string,List<>>
string 是来源
List<Goods> goodsList = new List<Goods>(); Goods good1 = new Goods(); good1.GoodsNumber = 1001; good1.Title = "iphone4"; good1.GoodsForm = "京东"; goodsList.Add(good1); Goods good2 = new Goods(); good2.GoodsNumber = 1002; good2.Title = "HTC G11"; good2.GoodsForm = "京东"; goodsList.Add(good2); Goods good3 = new Goods(); good3.GoodsNumber = 1003; good3.Title = "三星NOTE2"; good3.GoodsForm = "天猫"; goodsList.Add(good3); Goods good4 = new Goods(); good4.GoodsNumber = 1004; good4.Title = "联想乐phone"; good4.GoodsForm = "天猫"; goodsList.Add(good4); Goods good5 = new Goods(); good5.GoodsNumber = 1005; good5.Title = "小鬼当家漫画"; good5.GoodsForm = "当当网"; goodsList.Add(good5); Dictionary<string, List<Goods>> result = new Dictionary<string, List<Goods>>(); foreach (var item in goodsList) { if (!(result.ContainsKey(item.GoodsForm))) { result.Add(item.GoodsForm, new List<Goods>()); } result[item.GoodsForm].Add(item); }