❔ Return groups of results using LINQ?
I'm iterating through a set of data with LINQ.
The data's broken up into sections, where there's a "1" in the "NewSection" column on the first row of a new section, otherwise there's a "0" in that column.
I want to make a function that returns an Enumerable of Enumerables of my data rows, where the inner enumerable is all the entries in each section.
How would I construct my loop for this?
11 Replies
The specific application is actually chapter and verse divisions in the text of a book. So there's a row for each verse, a "1" in the "IsABook" column at the start of each book, a "1" in the "IsAChapter" column at the start of each chapter, etc.
Here's what I figured out:
.GroupBy() maybe ?
How would that work?
I edited the code
I think GroupBy would work if I had the name of each chapter or a chapter number in a column of my data, but not if I just have a "1" for the start of a new chapter
let me write an example
doubt groupby would work here
Samarichitane#3472
REPL Result: Success
Console Output
Compile: 605.878ms | Execution: 106.237ms | React with ❌ to remove this embed.
lol
Just pass chapter number
there you go
But my source data doesn't have chapter number, hence the question
Yeah if I had the chapter number in a column, that would make this real easy
I didn't make this and I'm trying to convert this data into something that's nicer for computers to read for the future.
Still you can pass as a value tuple
(IsABook, IsAChapter)
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.