Based on the following code:
var grouped = filters.GroupBy(p => p.PropertyName);
int numOfRowElements = grouped.Count();
foreach (IGrouping<string, PropertyFilter> filter in grouped)
{
foreach (var propertyFilter in filter)
{
// do something
}
}
where filters a List, my understanding is that calling IEnumerable.Count() forces the query to be executed. Is the result of this execution stored in the grouped variable, which is then used in the foreach loop, or does the foreach loop force the query to be executed again? Would it be better to do this instead?
var grouped = filters.GroupBy(p => p.PropertyName).ToList();
int numOfRowElements = grouped.Count;
foreach (IGrouping<string, PropertyFilter> filter in grouped)
{
foreach (var propertyFilter in filter)
{
// do something
}
}
TIA.