难以置信的看起来像是一个简单的问题。我有linq last last的平均值
var SummaryCollection = (from n in ...long criteria with group by clause)
into g select new
{ MonthYear = g.Key,
Amount = g.Sum(p=>p.Amount)}).OrderBy(p=>p.MonthYear);
}
我现在得到看起来像这样
Jan2009 $100
Feb2009 $134
... and so on
数据最后我有
decimal avgAmount = (from x in SummaryCollection select x.Amount).Average();
我现在需要得到的最后N个月的平均值,其中N是输入用户的文本框。 请建议如何使用Linq从有序集合中获取最后N个的平均值。谢谢
+1。请注意,如果您不能重新迭代集合,而不是Count()可能不是非常高性能的选择......不确定如何通过单次迭代来完成此操作。 –
@AlexeiLevenkov:正如我在解决方案中所展示的那样,可以使用队列。 – recursive
thx @BrokenGlass – Gullu