score:2
If there is no common sub-class among these element types, you can use LINQ to project the lists using a generic Tuple<int, int, object>
(i.e. rating, vote, and the original element instance) containing the two properties you are interested in. Then you can do a simple query to pick the top 10 elements:
List<A> ax = /* ... */;
List<B> bx = /* ... */;
List<C> cx = /* ... */;
/* ... */
IEnumerable<Tuple<int, int, object>> ratingsAndVotes =
ax.Select((a) => Tuple.Create(a.Rating, a.Vote, a)).Concat(
bx.Select((b) => Tuple.Create(b.Rating, b.Vote, b)).Concat(
cx.Select((c) => Tuple.Create(c.Rating, c.Vote, c)) /* ... */;
Tuple<int, int, object>[] topTenItems =
ratingsAndVotes.OrderByDescending((i) => i.Item1).ThenByDescending((i) => i.Item2).Take(10).ToArray();
// topTenItems now contains the top 10 items out of all the lists;
// for each tuple element, Item1 = rating, Item2 = vote,
// Item3 = original list item (as object)
score:8
Try something like below
var topTen = yourList.OrderBy(x => x.Rating).ThenBy(z => z.Vote).Take(10)
score:3
You can start with something like:
var res = l1.Concat(l2).Concat(l3).Concat(l4).Concat(l5)
.OrderByDescending(k => k.Rating)
.ThenBy(k=>k.Vote)
.Take(10).ToList();
where l1...l5 are your lists
score:1
You can use OrderBy and ThenBy to order by two (or more) fields and then use Take to get the top 10:
var myList = new List<Film>();
// ... populate list with some stuff
var top10 = myList.OrderBy(f => f.Rating).ThenBy(f => f.Vote).Take(10);
Hope that helps :)
Source: stackoverflow.com
Related Articles
- Find object inside collection of List
- C# LINQ Find List Inside Another List, Better way to code this than a foreach loop
- Find all items whose collection property contains items in another list
- How can I find object in List with Linq?
- LINQ to EF - Find records where string property of a child collection at least partially matches all records in a list of strings
- how to find minimum difference object of collection in c# linq
- Find rows where child collection contains all elements of the list
- List Inside IQueryable Object
- How to find how many times the same object appears in a list and then find a property of the most appeared object
- Using Linq find first object in list sorting by property A, then property B
- LINQ: single list which consists of multiple properties of same type of object collection
- find item inside list of list
- find object from Tree or List Hierarchy
- Find the List index of the object containing the closest property value
- How to find the peak 3D coordinate inside a list of 3D coordinates using LINQ?
- Find an Object that contains a string in a list of strings using LINQ
- LINQ returns arrays, not a collection of list object
- get property value from object collection list
- Find object in list with given property value then find dictionary value
- LINQ Search in collection of object containing object which contains list
- Given a list of color objects, find the most/least frequently existing color, and return that as a color object
- Using find method of the list collection
- Find an object within a list and replace its value
- linq find in which position is my object in List
- Converting Generic List of object to defined collection class with Lambda and C#
- Find distinct values from a list of object by one field only
- Combine contents of list member of object collection into single list with linq
- Use LINQ to find value inside a nested collection
- C# LINQ - Find object in list between two properties
- Xml parse object inside of list of objects inside object using LINQ
- Narrowing down where LINQ expression error is occurring
- Linq with group by in datatable
- How to get what exist in the first datatable and not exist in the second data table in a third one?
- What is the best way to make a LINQ-to-XML statement dynamic?
- LINQ: How to introduce where in Include?
- Select colon value by using linq
- LINQ to Entities - updating binary field
- Is LINQ's Any method efficient?
- ThenInclude not recognized in EF Core query
- How to avoid embedded (inline) images when saving outlook email attachments
- Informix to linq/sql
- SQL Server Compact compared to C# data structures
- Linq: Select data into multiple Lists
- Distinct on multiple fields
- How to left join tables in LINQ TO SQL to get associated records
- c# LINQ to object Autoincrement in subquery
- Linq where clause with multiple conditions and null check
- Linq find differences in two lists
- How do I to use Where, Group By, Select and OrderBy at same query linq?
- linq to DB search with contains