This commit is contained in:
Javier Suárez Ruiz 2021-10-14 19:29:52 +02:00
Родитель 412bd078aa
Коммит b20c2b673d
3 изменённых файлов: 58 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.31812.386
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LinqChunkSample", "LinqChunkSample\LinqChunkSample.csproj", "{8A089784-8E32-43A5-9461-548CDE24121E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8A089784-8E32-43A5-9461-548CDE24121E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8A089784-8E32-43A5-9461-548CDE24121E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8A089784-8E32-43A5-9461-548CDE24121E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8A089784-8E32-43A5-9461-548CDE24121E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {43C21616-4141-4B25-87BB-C7080A1C9953}
EndGlobalSection
EndGlobal

Просмотреть файл

@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
</Project>

Просмотреть файл

@ -0,0 +1,25 @@
using System;
using System.Linq;
namespace LinqChunkSample
{
internal class Program
{
static void Main(string[] args)
{
// Create a 100 items array
var range = Enumerable.Range(1, 100).ToArray();
// Split the collection into chunks of 20
var chunks = range.Chunk(size: 20).ToList();
// Chunk() takes a size parameter and then split the collection into small collections with the number of elements as specified by the size.
for (var i = 0; i < chunks.Count(); i++)
{
Console.WriteLine($"Chunk {i}");
Console.WriteLine(string.Join(",", chunks[i]));
}
}
}
}