I have a collection of sections and each section has a collection of questions. If I want to select all the questions under all the sections, this works
Sections.SelectMany(s=>s.Questions)
But now I also want the section number. So if I try something like this
Sections.SelectMany(s=>s.Questions,s.SectionNumber)
it throws compilation error.
How do I make this work?
You should use anonymous type here:
Sections.SelectMany(s => s.Questions, (s, q) => new { Question = q, s.SectionNumber })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With