score:2
Accepted answer
You may use the following:
list = list.Select(x => x.Where(i => i % 2 == 1).ToList())
.Where(x => x.Any())
.ToList();
Here, we're using Select()
to iterate the elements of the outer list, then using Where()
to filter the inner list. After that, we call Where()
on the outer list to filter out empty inner lists. That last part is optional; feel free to remove it if you need to keep empty lists.
Note: As @Dmitry stated in the comments, it's probably better to use i % 2 != 0
if you want to keep negative odd numbers.
Source: stackoverflow.com
Related Articles
- Search by zip code and filter list within specific radius?
- List or Array of String Contain specific word in Html Source Code
- c# Linq or code to extract groups from a single list of source data
- How to filter a list based on another list using Linq?
- Filter a list by another list C#
- Filter linq list on property value
- Simplest way to filter value from generic List in C# using LINQ
- In C#, how can I filter a list using a StartsWith() condition of another list?
- Linq query to filter id inside a list of list c#
- Generating the Shortest Regex Dynamically from a source List of Strings
- Enumerating through list of expressions to filter collection
- How can I filter a list of objects using lambda expression?
- How do you filter a list so that no member is a substring of another member
- Filter large list based on date time
- Most performant way to filter a huge List in C#?
- What is the fastest way to filter a list of strings when making an Intellisense/Autocomplete list?
- LINQ Source Code Available
- Use linq expression to filter a dictionary with a list of keys
- C# Filter Items In A List According To Multiple Criteria
- LINQ: Filter the list according to the math condition above elements in another list
- Writing a function to filter a list of a items by a property on it's base type in c#
- .NET 4 Code Contracts: "requires unproven: source != null"
- C# How to filter a list and remove duplicates?
- Filter duplicates from list
- How to filter list in asp.net/vb.net using linq
- Linq expression to filter an a list of entity's collection, and maintain list of entities
- Linq to filter nested list
- Filter a hierarchical list using linq
- How can I use drop down list value (String) to filter linq results?
- Using LINQ to filter a list of items based on those items' presence in another list
- Null reference in lambda max count
- How to convert SQL statatement containing a "NOT IN" constraint to its equivalent LINQ?
- Sort List with two parameters but in different lines of code
- how to add a child node inside a nother child node
- Comparison operators not supported for type 'System.String[]'
- Cannot convert system.generic.list anonymous type
- How can I make a more efficient Entity Framework LINQ call than a nested loop
- How to "prefix" order by expression using dynamic-linq
- C# how do I implement inheritance using linq?
- Compare Datetime's Year in LINQ return incorrect result
- How can i fix this error? c# asp linq
- Performing batch update in self referencing table
- linq join query get single record from second table
- Using date comparison in LINQ when querying SharePoint OData service
- Query seems to be really slow if there is no result set to return
- Setting a dynamic sort name field in a linq query
- How Can I Match Orders to Products?
- Parsing xml with xmlns in visual basic
- Duplicates in results from .ToArray in LinQ query
- Call function using Mongodb-CSharp Driver