需求:
例如
A B C
----------
1 1 a
1 2 a
1 3 a
1 4 b
1 5 a
2 6 a
2 7 b
2 8 b
得出结果: 要A.C相同 ,B连续递增
A B C
----------
1 1 a
1 2 a
1 3 a
2 7 b
2 8 b
实现代码:
void Main()
{
var list=new List<temp>
{
new temp{ A=1, B=1, C="a"},
new temp{ A=1, B=2, C="a"},
new temp{ A=1, B=3, C="a"},
new temp{ A=1, B=4, C="b"},
new temp{ A=1, B=5, C="a"},
new temp{ A=2, B=6, C="a"},
new temp{ A=2, B=7, C="b"},
new temp{ A=2, B=8, C="b"}
};
var result= new List<temp>();
var query=list.Aggregate((m,n)=>
{
if(m.A ==n.A && m.C==n.C)
{
if(m.B==n.B-1)
{
result.Add(m);
result.Add(n);
return n;
}
else
{
return m;
}
}
else{return n;}
}
);
Console.WriteLine("A\tB\tC");
result.Distinct().ToList().ForEach(r=>Console.WriteLine("{0}\t{1}\t{2}",r.A,r.B,r.C));
/*
A B C
1 1 a
1 2 a
1 3 a
2 7 b
2 8 b
*/
}
class temp
{
public int A{get;set;}
public int B{get;set;}
public string C{get;set;}
}