I was about to write such an extension
But then desided to google for it first, and voila:
Code:
public static IEnumerable<IEnumerable<TSource>> TakeBy<TSource>(this IEnumerable<TSource> source, int count)
{
if (source == null)
{
throw new ArgumentNullException("source");
}
if (count < 1)
{
throw new ArgumentOutOfRangeException("count");
}
while (source.Any())
{
yield return source.Take(count);
source = source.Skip(count);
}
}
got it here
Isn't it nice?
ps:
this variant is much faster
No comments:
Post a Comment