I have a dictionary of jobs which need writing to XML for site map usage.

I cannot have the files going over 50,000 records and so need a way of paging this information or something along these lines.

This method decides if the total number of jobs is greater than 30,000.

How could I change my else to include paging?

有帮助吗?

解决方案

Add Skip before Take in your (inner) for loop.

int newJobCount = JobCount / 4;

for (int i = 0; i < 4; i++)
{
          Test(item.Value.BrandName, item.Value.CountryCode, item.Value.Jobs.Values.Skip(newJobCount * i).Take(newJobCount).ToList());
}

See http://geekswithblogs.net/BlackRabbitCoder/archive/2012/03/29/c.net-little-wonders-skip-and-take.aspx.

Side note regarding newJobCount

If you want to limit number of jobs per page to 3000, then following will be better:

int pageCount = JobCount/3000 + (JobCount % 3000 == 0 ? 0 : 1);

for (int i = 0; i < pageCount; i++)
{
    Test(item.Value.BrandName, item.Value.CountryCode, item.Value.Jobs.Values.Skip(3000 * i).Take(3000).ToList());
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top