using System; using System.Collections.Generic; namespace Sony.Filtr.Utility.Extensions { public class Batch { public readonly int Offset; public readonly int Limit; public Batch(int offset, int limit) { this.Offset = offset; this.Limit = limit; } } public static class IntExtensions { public static Batch[] Batch(this int total, int batchSize) { var batches = new List(); int currentOffset = 0; int currentLimit = 0; while (currentOffset < total) { currentLimit = (total - currentOffset) > batchSize ? batchSize : total - currentOffset; batches.Add(new Batch(currentOffset, currentLimit)); currentOffset += currentLimit; } return batches.ToArray(); } } }