score:12
Accepted answer
Use SelectMany
to flatten nested lists
asparaguses.AddRange(field.GetBeds().SelectMany(bed => bed.GetAsparaguses()));
score:6
Try SelectMany
in order to flatten the collection of collection:
asparaguses.AddRange(field
.GetBeds()
.SelectMany(bed => bed.GetAsparaguses()));
Source: stackoverflow.com
Related Query
- Use Linq to flatten a nested list instead of a foreach loop
- LINQ instead of foreach and list.addrange
- C# - Linq optimize code with List and Where clause
- Linq ForEach with AddRange and Contains And Select
- How to remove selected data that found on another list and take last 6 id through LINQ without foreach loop
- Compare two list in C# and reject or select the child list based on conditions using LINQ or foreach
- C# LINQ code for two list compare and replace
- C# LINQ Find List Inside Another List, Better way to code this than a foreach loop
- LINQ instead of nested foreach and if
- How to use Linq instead of foreach to Group and Count
- Getting rid of outer foreach loop using linq or lambda and ensuring no duplicates are added to list
- c# Linq or code to extract groups from a single list of source data
- How to write SQL translateable linq code that groups by one property and returns distinct list
- linq to retrieve name instead of id and list in descending order
- Convert list to dictionary using linq and not worrying about duplicates
- compare two list and return not matching items using linq
- Simple LINQ and List error: WhereListIterator`1[Task]' to type 'System.Collections.Generic.List`1[Task]'
- C# Groupby Linq and foreach
- Linq way to get piecewise difference between element and next element in list
- LINQ Get Distinct values and fill LIST
- Use LINQ and C# to make a new List from an old List
- Joining multiple where clauses in LINQ as OR instead of AND
- How to update an element with a List using LINQ and C#
- why ForEach Linq Extension on List rather than on IEnumerable
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- Sorting a list of <Object> with VB and LINQ
- Sort a list and all its nested objects using LINQ
- Convert a list to a dictionary and sum up values using linq
- Add quotes at the beginning and end of each element in list using LINQ
- LINQ with subselect and groupby to get only the latest version of each item in a list
More Query from same tag
- IQueryable parameters - how to view?
- LINQ - Grouping a list by multiple properties and returning an object with an array member
- Distinct() doesn't work
- How can I create a Linq AND expression in C#?
- Retrieve data from an object in C#
- Using LINQ within a 'foreach' loop only running once
- Bitwise operation with grouping using Linq
- Ignore duplicated rows with LINQ
- Does accessing MemoryCache create a copy?
- What is the Maximum Number of Records i can insert through InserAllOnSubmit() In Linq to Sql
- How to do multiple left outer joins in a Linq Query?
- Return an array of integer when there is only one element using linq to xml
- linq combining 2 queries
- Linq to return only selected columns from table
- convert this LINQ expression into Lambda
- Selecting an Entity into a property of an object won't populate its related entities despite .Include() being used. Why is this?
- Comparing two string arrays in C#
- Date comparison format in stored procedure
- How to deep look into all possible linked objects?
- How do I specify LINQ's OrderBy direction as a boolean?
- Custom Union in Linq to Entities
- C# get differences in two matching lists
- Get objects from collection with Linq
- Find Min and Max value in table between given variable in C#
- converting SQL double in String
- LINQ query performance when applying Where clause
- How to avoid checking particular 'linq where clause' if that value is "any"?
- Join 2 DataTables on dynamic number of columns
- Not Parsing XML Data Correctly with Linq to XML
- Creating a breadcrumb like hierarchy using LINQ