Is there any way I can separate a List
into several separate lists of SomeObject
, using the item index as the delimiter of each s
Old code, but this is what I've been using:
public static IEnumerable> InSetsOf(this IEnumerable source, int max)
{
var toReturn = new List(max);
foreach (var item in source)
{
toReturn.Add(item);
if (toReturn.Count == max)
{
yield return toReturn;
toReturn = new List(max);
}
}
if (toReturn.Any())
{
yield return toReturn;
}
}