Skip to content

Instantly share code, notes, and snippets.

@akamud
Created May 24, 2021 21:09
Show Gist options
  • Save akamud/f19ee8d4b658b1c4a5805bd23b70372f to your computer and use it in GitHub Desktop.
Save akamud/f19ee8d4b658b1c4a5805bd23b70372f to your computer and use it in GitHub Desktop.
Código exemplificando o novo método Chunk do IEnumerable
using System;
using System.Collections.Generic;
using System.Linq;
var listaGrande = Enumerable.Range(1, 100);
foreach (var lote in listaGrande.Chunk(10))
{
// Cada lote aqui tem no máximo 10 itens
Acao(lote.ToList());
}
static void Acao(ICollection<int> lote)
{
Console.WriteLine($"Processando lote de {lote.Count} itens");
Console.Write("[");
foreach (var item in lote)
{
Console.Write($"{item},");
}
Console.WriteLine("]");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment