From the course: Ten Tips for the C# Developer

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Work with nested collections and SelectMany

Work with nested collections and SelectMany - C# Tutorial

From the course: Ten Tips for the C# Developer

Start my 1-month free trial

Work with nested collections and SelectMany

- [Instructor] In this tip, we're looking at a LINQ Query Operator called SelectMany. I find this Query Operator useful for flattening sub-collections if you've got data, multiple collections deep, you can use SelectMany to flatten and get a more readable view in some of your queries. And if you like this tip, you'll find other LINQ Queries in my LINQ essential training course. I'll be using LINQPad to run this code, LINQPad stores it's queries in a file that ends with .linq, so what I've got for you is in this LINQPad folder, there's this file in tip number 10 and what I'm going to do is right click here and choose to open folder in File Explorer, then I'll double click on this SelectMany.linq file that launches LINQPad. If you want to get your own copy of LINQPad, you can get a free version here at linqpad.net. So here's the idea, SelectMany flattens a one to many relationship, another way of saying that is it can…

Contents