我们如何使用分组范围来表示等于或大于?
var data = new[] {
new { Id = 0, Price = 2 },
new { Id = 1, Price = 10 },
new { Id = 2, Price = 30 },
new { Id = 3, Price = 50 },
new { Id = 4, Price = 120 },
new { Id = 5, Price = 200 },
new { Id = 6, Price = 1024 },
};
var ranges = new[] { 10, 50, 100, 500 };
var grouped = data.GroupBy( x => ranges.FirstOrDefault( r => r > x.Price ) );
grouped ouput is
price 10-50 -> 3
price 50-100 -> 1
price 100-500 -> 2
所需输出按照使用的范围相等或大于该范围分组
price >= 10 -> 6
price >= 50 -> 4
price >= 100 -> 3
price >= 500 -> 1