Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Common.Extensions
- {
- public static class IEnumerableExtensions
- {
- public static IEnumerable<List<T>> InSetsOf<T>(this IEnumerable<T> source, int max)
- {
- List<T> toReturn = new List<T>(max);
- foreach (var item in source)
- {
- toReturn.Add(item);
- if (toReturn.Count == max)
- {
- yield return toReturn;
- toReturn = new List<T>(max);
- }
- }
- if (toReturn.Any())
- {
- yield return toReturn;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment