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<DataRow> 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<List<DataRow>> chunks = new List<List<DataRow>>();
- IEnumerable<DataRow> 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());
Best Regards
Brian Dahl