-1

I have a List<Items> for example 365 elements

    public DateTime DayD { get; set; }
    public double Day { get; set; }
    public double Week { get; set; }
    public double Month { get; set; }

How to pass through the list by period 30 day - mean for each element select next 30 element.

  • 1
    Do you mean List> ? Where inner list contains List of 30 element. – Yogee Sep 25 '14 at 13:11
  • 2
    Mean List => List => List etc... 9/25/2014 to 9/25/2015 first group would be a 9/25/2014 - 10/25/2014 next 9/26/2014/ - 10/26/2014 and up to end – Nikky Rubin Sep 25 '14 at 13:14

1 Answers1

2

I would use LINQ with a yield return, something like :

static IEnumerable<List<Item>> GetXMany(int pageSize)
{
    for (int i = 0; i < items.Count(); i+=pageSize)
    {
        yield return items.Skip(i).Take(pageSize).ToList();
    }
}

and loop through it with :

foreach (List<Item> items in GetXMany(30))
{

}
Jonesopolis
  • 25,034
  • 12
  • 68
  • 112