Skip to content

Instantly share code, notes, and snippets.

@sapher
Last active August 29, 2015 14:04
Show Gist options
  • Save sapher/08d7ee48722e9abae6c5 to your computer and use it in GitHub Desktop.
Save sapher/08d7ee48722e9abae6c5 to your computer and use it in GitHub Desktop.
List extension that help split a list into smaller chuncks of n size
using System;
using System.Collections.Generic;
using System.Linq;
namespace Core.Extensions
{
public static class ListExtension
{
public static IEnumerable<IEnumerable<T>> Split<T>(this List<T> list, int size)
{
for (var i = 0; i < Math.Ceiling((float)list.Count / size); i++)
{
yield return list.Skip(i * size).Take(size);
}
}
}
}
//Use > var chuncks = list.Split(10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment