0

I have the string of comma separated ids like 1,2,3,4,5,6,7,8,9...... etc.

Please suggest how i can split them in group of "Quantity" means if Quantity=3 then group are (List) ["1,2,3"], ["4,5,6"], ["7,8,9"] etc.

Range of Quantity is from 1-75.

  • 1
    possible duplicate of [Split List into Sublists with LINQ](http://stackoverflow.com/questions/419019/split-list-into-sublists-with-linq) – Farhad Jabiyev Mar 21 '15 at 08:01

1 Answers1

2

Try this:

var quantity = 3; 

yourList.Select((x, i) => new { Index = i, Value = x })
        .GroupBy(x => x.Index / quantity )
        .Select(x => x.Select(v => v.Value).ToList())
        .ToList();
RagtimeWilly
  • 5,265
  • 3
  • 25
  • 41