Last active
August 29, 2015 14:04
-
-
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
This file contains 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; | |
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