Is there a more elegant way to implement going 5 items at a time than a for loop like this?
var q = Campaign_stats.OrderByDescending(c=>c.Leads).Select(c=>c.PID).Take(23);
var count = q.Count();
for (int i = 0; i < (count/5)+1; i++)
{
q.Skip(i*5).Take(5).Dump();
}
So you want to efficiently call
Dump()on every 5 items inq.The solution you have now will re-iterate the
IEnumerable<T>every time through theforloop. It may be more efficient to do something like this: (I don’t know what your type is so I’m usingT)This only uses one iterator. Considering your variable is named
q, I’m assuming that is short for “query”, which implies this is against a database. So using just one iterator may be very beneficial.I may keep this code, and wrap it up in an extension method. How about “clump”?
Calling it in the context of your code: