Say I have this:
// ------------------------
IEnumerable<myType> foo = ....;
// grouping my results by day, then ordering the groups from oldest to newest
var fooOrderedGrouping = foo.GroupBy(f => f.DateTime.Date).OrderBy(g => g.Key);
DateTime firstDay = fooOrderedGrouping.First().Key;
DateTime lastDay = fooOrderedGrouping.Last().Key;
int firstDayCount = fooOrderedGrouping.First().Count();
int lastDayCount = fooOrderedGrouping.Last().Count();
// -------------------------
Are the results of First() and Last() cached? or is it reexecuted every time?
Because I could restructure it like this:
// ----------------------------
var firstGroup = fooOrderedGrouping.First();
var lastGroup = fooOrderedGrouping.Last();
DateTime firstDay = firstGroup.Key;
DateTime lastDay = lastGroup.Key;
int firstDayCount = firstGroup.Count();
int lastDayCount = lastGroup.Count();
// ------------------------------
which, to me, seems like the First() and Last() methods will only be hit once
// ------------------------
IEnumerable<myType> foo = ....;
// grouping my results by day, then ordering the groups from oldest to newest
var fooOrderedGrouping = foo.GroupBy(f => f.DateTime.Date).OrderBy(g => g.Key);
DateTime firstDay = fooOrderedGrouping.First().Key;
DateTime lastDay = fooOrderedGrouping.Last().Key;
int firstDayCount = fooOrderedGrouping.First().Count();
int lastDayCount = fooOrderedGrouping.Last().Count();
// -------------------------
Are the results of First() and Last() cached? or is it reexecuted every time?
Because I could restructure it like this:
// ----------------------------
var firstGroup = fooOrderedGrouping.First();
var lastGroup = fooOrderedGrouping.Last();
DateTime firstDay = firstGroup.Key;
DateTime lastDay = lastGroup.Key;
int firstDayCount = firstGroup.Count();
int lastDayCount = lastGroup.Count();
// ------------------------------
which, to me, seems like the First() and Last() methods will only be hit once
