日期:2014-05-20 浏览次数:20715 次
void Main() { int[] num = new int[] { 1, 1, 2, 3, 4, 6, 6, 7, 7, 7, 8, 10 }; int[] N_value = new int[] { 10, 10, 13, 15, 20, 40, 40, 100, 100, 100, 90, 95 }; var query=(from n in num.Select((x,index)=>new{x,index}) join v in N_value.Select((x,index)=>new{x,index}) on n.index equals v.index select new{n.x,v=v.x}).GroupBy(x=>x.x).Select(g=>new{g.Key,s=g.Sum(x=>x.v)}); query.ToList().ForEach(q=>Console.WriteLine("{0}\t{1}",q.Key,q.s)); /* 1 20 2 13 3 15 4 20 6 80 7 300 8 90 10 95 */ }