Created
August 17, 2022 13:51
-
-
Save wbokkers/55780cd7620365db6f9d3dd41af350e9 to your computer and use it in GitHub Desktop.
Create chunks from 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 IEnumerable<ArraySegment<T>> Chunk<T>(T[] source, int chunkSize) | |
{ | |
for (int i = 0; i < source.Length; i += chunkSize) | |
{ | |
var remaining = source.Length - i; | |
var segmentSize = Math.Min(chunkSize, remaining); | |
yield return new ArraySegment<T>(source, i, segmentSize); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment