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 Query
- How to filter a list based on another list using Linq?
- In C#, how can I filter a list using a StartsWith() condition of another list?
- 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
- C# How to filter a list and remove duplicates?
- How to filter list in asp.net/vb.net using linq
- How can I use drop down list value (String) to filter linq results?
- How do I filter a list containing another list in C#?
- How to filter a list with linq depends on counting a property at the same list and take a random group at least minimum total
- How to filter data in a list using multiple conditions and LINQ?
- How do I filter a strongly typed list with List<String> variables
- How can i copy data table records of different field name based on mapping list evaluating condition on source data table?
- How to enumerate through list of Func<TSource,TResult> to filter collection
- How to filter list that has date and retrieve only data within 7 days
- How can I filter a list using generics and Linq extension methods?
- how to filter list which is inside List of class using linq?
- How to efficiently filter objects out of an (initially) large list of objects
- How do you filter out data that exists in a list from a Query?
- How do you convert a List of object to a one dimensional array?
- How to filter a list using an async predicate
- How to filter list of dictionary values with criteria
- Search by zip code and filter list within specific radius?
- How do I filter a list within a list while maintaining the original form of the object using linq?
- How can you filter list by property value in an int list?
- C# linq how to filter a list of groups by the objects in the group
- How to filter list of classes by property name?
- How to loop through a child list of objects in Entity Framework 4.1 code first
- How to filter linq query based on all of the values of one property from another list
- How to filter List with multiple 'and' 'or' conditions
- How to filter List With LINQ C#
More Query from same tag
- C# - Linq with two Lists
- Identifying and grouping similar items in a collection of strings
- Check byte array contains byte array linq c#
- Linq expression to find the max value of a List<List<int>>?
- How to show the filenames under the selected folder on the Radio Button
- LINQ OrderBy with index ; getting error using Generic TKey
- Querying an XML log with LINQ
- Changing field value after querying does not take effect
- Linq join 2 entities on a single field and return the matching entries
- linq looping through tags with the same name
- How to get the count of the values that are repeated in c#
- .net Linq command doesn't return certain fields
- Mongodb C# Driver Unsupported filter error with specific linq predicate
- Getting the highest date from a list
- Remove items from an Object [] that are contained in a custom class array
- Linq to Entities parameterless constructor requirement ruins potential for lazy querying
- LINQ query on a list of Object[] arrays
- How to use Group By with Task<IEnumerable<Entity>> in LINQ
- At least one object must implement IComparable in Max()
- Custom sorting with LINQ
- Refactor LINQ ForEach to return IEnumerable<T>
- Stripping data from a EPPlus output, from a date range
- ISNULL equivalent in Linq
- select as field in Linq
- Can't figure out the right linq query for this
- Building OrderBy-expression at runtime by property-name which can be nested
- How I get the right Data from my Column with Linq
- SQL Query to LINQ for MVC with SUM and IS NOT NULL
- How can I tell why/how some LINQ queries work with each other and others don't?
- Entity Framework - Eager loading Linq query