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 - C# Tutorial
From the course: Ten Tips for the C# Developer
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
-
-
-
Avoid race condition with TryGetValue method1m 46s
-
Better switch statements with pattern matching6m 42s
-
Readable literals with the underscore4m 8s
-
Extract items from sequence with indices9m 8s
-
Discard feature5m 3s
-
Be more functional with the conditional operator2m 42s
-
Create a thread-safe immutable type5m 13s
-
Use the ImmutableList collection4m 14s
-
Show custom debugger information4m 49s
-
Work with nested collections and SelectMany2m 45s
-
-