Successfully added
C#
by Jerry
How to query a list within list using LINQ
When dealing with nested lists in C# and needing to flatten them, LINQ's SelectMany
method comes in handy. Here's a simple example:
var orders = new List<Order>();
var distinctOrderLines = orders.SelectMany(order => order.OrderLines).Distinct();
This code snippet flattens the orders
list containing lists of OrderLines into a single sequence of distinct OrderLines
.
For more information and examples, you can refer to these resources
Referenced in:
Comments