Hi i have the following Problem. I have a list and i want to divide the List into sub-lists dependend from a value from a cell.
For Example:
I have a List and in the column "Name" from every DataRow start the Sublist with the value "Start" and end it with "End".
I have solved it with the following code, but i want to know if there is a more efficent way to solve it?
- var rowsFromTable = table.AsEnumerable().ToList();
- List
- > chunks = new List
- >();
- IEnumerable
rest; - do
- {
- rest = rowsFromTable.Except(chunks.SelectMany(c => c));
- var extractRows = rest.TakeWhile((row, index) => (string)row["Name"] != "Start" || index == 0).ToList();
- chunks.Add(extractRows);
- }
- while(rest.Any());
Brian Dahl
Shrimant TelgavePosted Jul 6, 2018, 4:12 AM
Your code is correct but If you want different soultion for the same then please find the below link.
https://stackoverflow.com/questions/419019/split-list-into-sublists-with-linq