Created
September 2, 2015 21:43
-
-
Save morbidcamel101/f7c58f3b77967ca3daf9 to your computer and use it in GitHub Desktop.
Split Array
This file contains hidden or 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
| 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