Skip to content

Instantly share code, notes, and snippets.

@morbidcamel101
Created September 2, 2015 21:43
Show Gist options
  • Select an option

  • Save morbidcamel101/f7c58f3b77967ca3daf9 to your computer and use it in GitHub Desktop.

Select an option

Save morbidcamel101/f7c58f3b77967ca3daf9 to your computer and use it in GitHub Desktop.
Split Array
public static IEnumerable<T[]> Split<T>(this T[] array, int blockSize)
{
List<T> list = new List<T>();
for(int i = 0; i < array.Length; i++)
{
if (i % blockSize == 0)
{
if (list.Count > 0)
yield return list.ToArray();
list.Clear();
}
list.Add(array[i]);
}
if (list.Count > 0)
yield return list.ToArray();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment