LINQ Take(); how to handle when null or fewer records than requested available?

There’s a difference between a null reference and an empty collection. It’s fine to call Take on an empty collection. And the argument specifies a maximum number to take, so it’s also fine to specify more than there are items in the collection. I recommend referring to MSDN for precise details like this. For Linq … Read more

LINQ Partition List into Lists of 8 members [duplicate]

Use the following extension method to break the input into subsets 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 … Read more