I have a list of items and I need to loop through it so that every n (eg. 3) items are first collected and then processed at once at the n'th item.
I'm doing the following:
List<MyObject> smallList = new List<MyObject>(); for (int i = 0; i < largeList.Count; i++) { smallList.Add(largeList[i]); if (i % 3 == 0 || i >= largeList.Count - 3) { //Do somehting with those n items... } smallList.Clear(); } Is there a better way to do the above?