c# 4.0 - split List<User> in multiple List<User> in c# -
i want split list of user generic list small list each 5 records.
ex
i have list: u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,u15. must split list1:u1,u2,u3,u4,u5 list2:u6,u7,u8,u9,u10 list3:u11,u12,u13,u14,u15
any direct method available or need programing logic in c# ?
you can group on index:
list<list<user>> lists = list .select((u, i) => new { list = / 5, user = u }) .groupby(g => g.list, g => g.user) .select(g => g.tolist()) .tolist();
you can use range
make loop , part of list each iteration:
list<list<user>> lists = enumerable.range(0, (list.count + 4) / 5) .select(n => list.skip(n * 5).take(5).tolist()) .tolist();
Comments
Post a Comment