DEV Community

Cover image for LINQ SelectMany in Depth

LINQ SelectMany in Depth

Matt Eland on January 27, 2020

In this article, I’ll walk through the various overloads and usages of LINQ’s SelectMany methods. SelectMany is in many ways the opposite of Group...
Collapse
 
jessekphillips profile image
Jesse Phillips

If I understand your final index example should look like

books.SelectMany(
   (b, i) => b.Characters[i]...)

Or we could replace the result collector.

books.SelectMany(
   (b, i) => $"{b.Characters[i]} ({b.Title})")
Collapse
 
integerman profile image
Matt Eland

No, what I have there is correct and works properly.

Collapse
 
jessekphillips profile image
Jesse Phillips • Edited

I don't understand where characters comes from then. It looks undefined to me.

Thread Thread
 
integerman profile image
Matt Eland

Imagine it as a List<string> that comes from another file or data source outside of books