If you don't want to use a separate library, you can use a simple extension method to partition a sequence into subsequences of a given size:
public static class EnumerableExt
{
public static IEnumerable<IEnumerable<T>> Partition<T>(this IEnumerable<T> input, int blockSize)
{
var enumerator = input.GetEnumerator();
while (enumerator.MoveNext())
yield return nextPartition(enumerator, blockSize);
}
static IEnumerable<T> nextPartition<T>(IEnumerator<T> enumerator, int blockSize)
{
do yield return enumerator.Current;
while (--blockSize > 0 && enumerator.MoveNext());
}
}
Then you can use it like so:
// Create some sample strings.
var strings = Enumerable.Range(1, 10000).Select(x => x.ToString()).ToList();
var result = strings.Partition(500).Select(block => string.Join(",", block)).ToList();
This approach does not make a copy of the input array.