Created
May 24, 2021 21:09
-
-
Save akamud/f19ee8d4b658b1c4a5805bd23b70372f to your computer and use it in GitHub Desktop.
Código exemplificando o novo método Chunk do IEnumerable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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