Skip to content

Instantly share code, notes, and snippets.

@greenygh0st
Created April 15, 2020 13:27
Show Gist options
  • Save greenygh0st/10edfabccb0e6f2c5b89865b4f417b54 to your computer and use it in GitHub Desktop.
Save greenygh0st/10edfabccb0e6f2c5b89865b4f417b54 to your computer and use it in GitHub Desktop.
/// <summary>
/// Helper methods for the lists.
/// </summary>
public static class ListExtensions
{
public static List<List<T>> ChunkBy<T>(this List<T> source, int chunkSize)
{
return source
.Select((x, i) => new { Index = i, Value = x })
.GroupBy(x => x.Index / chunkSize)
.Select(x => x.Select(v => v.Value).ToList())
.ToList();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment