I have a list of items e.g
id
1
2
3
4
5
6
7
8
9
10
11
12
13
I want to write this to csv and do it in batches of 5 so when it reaches id 5 it will go to next batch. I was thinking of doing mod to cater for this so
int noOfIds = MyIDList.Count % 5; // to get the number of loops i need
List<MyIDList> topFiveID = (from c in MyIDList
select c).Take(5).ToList(); // get top 5 from the list
Then I am getting the rest by
List<MyIDList> restOfIDs = MyIDList.Where(c => !topFiveID.Any(tc => tc.ID == c.ID)).ToList();
Now I can see this can cater for up to 9 ids, can someone please tell me how to cater for all the ids no matter how many are there.
Hope it is clear enough.
The following will return batches of a given size from an enumeration:
Used like: