这是在 Linqpad 中:
var tuples = new[] {
Tuple.Create(1, 2012, 1, 1),
Tuple.Create(1, 2012, 1, 2),
Tuple.Create(1, 2012, 1, 3),
Tuple.Create(1, 2012, 1, 4),
Tuple.Create(1, 2012, 1, 5),
Tuple.Create(1, 2012, 2, 6),
Tuple.Create(1, 2012, 2, 7),
Tuple.Create(1, 2012, 2, 8),
Tuple.Create(1, 2012, 2, 9),
Tuple.Create(1, 2012, 2, 10),
Tuple.Create(1, 2013, 2, 1),
Tuple.Create(1, 2013, 2, 13),
Tuple.Create(1, 2013, 2, 14),
Tuple.Create(1, 2013, 2, 15),
Tuple.Create(1, 2013, 2, 16),
Tuple.Create(1, 2013, 3, 17),
Tuple.Create(1, 2013, 3, 18),
Tuple.Create(1, 2013, 3, 19),
Tuple.Create(1, 2013, 3, 20),
Tuple.Create(1, 2013, 3, 21)};
tuples
.GroupBy(t => t.Item3)
.Select (g => g.Where(x => x.Item2 == g.Max (x1 => x1.Item2)))
.Dump();
因此,您将获得一个学期中最高年份的学期。
输出:
Item1 Item2 Item3 Item4
1 2012 1 1
1 2012 1 2
1 2012 1 3
1 2012 1 4
1 2012 1 5
Item1 Item2 Item3 Item4
1 2013 2 1
1 2013 2 13
1 2013 2 14
1 2013 2 15
1 2013 2 16
Item1 Item2 Item3 Item4
1 2013 3 17
1 2013 3 18
1 2013 3 19
1 2013 3 20
1 2013 3 21