Adding
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
||||
namespace ReserveManagementSystemApi.Helpers
|
||||
{
|
||||
public static class BatchHelper
|
||||
{
|
||||
public static IEnumerable<IEnumerable<TSource>> CreateBatch <TSource>(
|
||||
List<TSource> source, int batchSize)
|
||||
{
|
||||
var items = new TSource[batchSize];
|
||||
var count = 0;
|
||||
foreach (var item in source)
|
||||
{
|
||||
items[count++] = item;
|
||||
if (count == batchSize)
|
||||
{
|
||||
yield return items;
|
||||
items = new TSource[batchSize];
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
yield return items.Take(count);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user