当我多年来最大化时,如何选择最大值所属的月份?
请考虑以下代码:
public class Data_Point
{
public int Month { get; set; }
public int Year { get; set; }
public int Value { get; set; }
}
static void Main(string[] args)
{
List<Data_Point> Data = new List<Data_Point>();
Data.Add(new Data_Point() { Month = 0, Year = 0, Value = 99 });
Data.Add(new Data_Point() { Month = 1, Year = 0, Value = 69 });
// Max should relate to one record only.
var Max_Year = (from e in Data
group e by e.Year into y
select new { Month( e => e.Month ), Year = y.Key, Value = y.Max(e => e.Value) }).ToList();
}
我知道我的问题在 SQL 中不太可能,但我想知道 LINQ 在这里是否更灵活。