0
public class Person
{
public int Id{get;set;}
public string Name{get;set;}
}
public class Test
{

private readonly IPersonDataService _personDataService;
public Test(IPersonDataService personDataService)
{
_personDataService=personDataService;
}

List<Person> persons=_personDataService.GetList();
List<List<Person>> personLists=new <List<Person>>();
}

Imagine the persons list contains 50 items.I want to be able to extract 5 lists of 10 items each from persons and add each list to personLists. In the end the personLists should have 5 items where each item is a List containing 10 items each.

zack
  • 3
  • 1

1 Answers1

0

Assuming the list persons always has 50 items, you can do something like this:

for (int listCount = 0; listCount < 5; listCount++) {
 List<Person> newList = new List<Person>();
 personLists.add(newList);
 for (int innerCount = 0; innerCount < 10; innerCount++) {
  newList.add(persons.next());
 }
}

Keep in mind this is untested, but the general concept should be sound.

nhouser9
  • 6,730
  • 3
  • 21
  • 42