I'm a C++ programmer so forgive any bad syntax, but this is where you can use a reference to a currentList
that varies as you create a new list each time one fills up, using an if
condition within your foreach
.
public void(List<string> sd)
{
// Create a list of lists to store your lists.
List<List<Item>> lists;
// We're going to use this variable to refer to our
// current, not-yet-full list (less than 10 items).
List<Item> currentList;
// Create the first list you'll be adding items to,
// and add it to our list of lists.
currentList = new List<Item>();
lists.Add(currentList);
foreach(var item in sd)
{
currentList.Add(new Item { Id = item});
if(currentList.Count() >= 10)
{
// This should look familiar from above :-)
currentList = new List<Item>();
lists.Add(currentList);
}
}
}
If I've got some syntax wrong, please feel free to edit and correct my answer.
>`?
– Yacoub Massad Dec 12 '15 at 13:19