//The MIT License (MIT)
//http://arolibraries.codeplex.com/license
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
namespace AroLibraries.ExtensionMethods.Enumerable
{
public static class IEnumerableExt
{
public static IEnumerable<IEnumerable<T>> Ext_Split<T>(this IEnumerable<T> source, int splitSize)
{
using (IEnumerator<T> enumerator = source.GetEnumerator())
{
while (enumerator.MoveNext())
{
yield return Ext_SplitInner(enumerator, splitSize);
}
}
}
private static IEnumerable<T> Ext_SplitInner<T>(IEnumerator<T> enumerator, int splitSize)
{
int count = 0;
do
{
count++;
yield return enumerator.Current;
}
while (count % splitSize != 0
&& enumerator.MoveNext());
}
}
}
|