Monday, March 18, 2013

c# split list into sub lists

public static List<List<T>> Split<T>(List<T> source)
        {
            return source
                .Select((x, i) => new { Index = i, Value = x })
                .GroupBy(x => x.Index / 4)
                .Select(x => x.Select(v => v.Value).ToList())
                .ToList();
        }

No comments:

Post a Comment