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: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 :)
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:8
try something like below
var topten = yourlist.orderby(x => x.rating).thenby(z => z.vote).take(10)
Source: stackoverflow.com
Related Query
- 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
More Query from same tag
- Distinct value using hashtable
- Linq query is triggered multiple times without any apparent reason
- Including values from external table in a LINQ statement
- Modify elements in list with ForEach lambda
- Unable to retrieve values using Lambda Expression
- List intersection by criteria in .NET
- How to check in all visible rows CELLs for string.IsNullOrEmpty and IsDateEmpty
- C# LINQ Joining And where statement not working
- Linq sort first two numbers in long type
- Getting all indexes of matching elements in string array
- Select a Dictionary<T1, T2> with LINQ
- ASP.NET LINQ query for filter and loop through multiple tables
- Comparing object with Nothing in vb.net
- Get distinct values from a datatable
- Left Outer Join in Linq to Entities / SQL
- Entity Framework - LINQ Expression Map many to many
- int -> int list is not compatible with type int -> IEnumerable<'a>
- Linq Select * from Table ExecuteQuery
- Implicitly typed local variables must be initialized
- Calculating the Hamming distance between two strings with LINQ
- Java Group Objects in Custom Manner
- Linq OrderBy not sorting correctly 100% of the time
- Save unicode character with linq to SQL
- What's faster? select [object] or select new {[object].value1, [object].value2} with linq
- Whether to use select or AsEnumerable().Where()
- C# Distinct in LINQ query
- Linq - where inside include
- Expression.Condition(nullableType.HasValue, new classInstance(){ ... }, null) can it be done some other way?
- Is .Select<T>(...) to be prefered before .Where<T>(...)?
- Linq to Entity Groupby and concatinate column