score:6
if a player name should only appear once you have to group the collection by player
and order each group by score
. then you can pick the highest 3.
var top3 = scores.groupby(x => x.player)
.select(x => x.orderbydescending(y => y.score).first())
.orderbydescending(x => x.score)
.thenby(x => x.player)
.take(3);
score:1
scores.groupby(i => i.player)
.select(g => g.orderbydescending(s => s.score).first())
.orderbydescending(i => i.score)
.thenby(i => i.player)
.take(3)
but there is a bonus up-vote for any solution that puts the person whose name appears first in the alphabet highest in the event that their scores are tied
thenby is used for tie-breaks on ordering.
idea is to group by player to get each players best score and then process that flat list.
score:4
you can group them and then pick the maximum score of each player, and then order them:
var top3 = scores.groupby(x=>x.player)
.select(g=>new
{
player=g.key,
score=g.max(p=>p.score)
})
.orderbydescending(s => s.score)
.thenby(p=>p.player).take(3);
Source: stackoverflow.com
Related Query
- How can I get the top three players and their high scores from a collection using linq and lambdas
- How can I filter a dictionary using LINQ and return it to a dictionary from the same type
- How do I get the latest date from a collection of objects using LINQ?
- How do I get the first value from this collection using Linq to Entities?
- How to get the second repeated item from a collection of objects using LINQ to object
- How can I check the number of calls to the database in LINQ query when using .NET Core and Code First?
- How to get the distinct record name and its each record count to bind to gridview in C# using Linq from SQL Server
- how can i get the right fields into a group and sum using linq?
- How can I get the next appropriate value from a generic list using LINQ?
- Using Linq how do get a list of users and their last login from two tables
- How do I group items from a collection using LINQ and return the shaped data according the collection type
- How can I get data from the Entity Framework if I only know the table name and the column name from which to get the data?
- How to get the whole record from a collection which has latest dateTime using linq?
- How to get the list of employees and their reporting level recursively using LINQ
- Using LINQ and Entity Framework, how can I just populate some properties of a Dbo with data from the DB?
- How to get the inner text from an xml document using XDocument and extension methods
- How can we get list of two column say firstname and lastname from customer table in mvc using linq query
- How to get the top 3 elements in an int array using LINQ?
- using LINQ how can i concatenate string properties from itesm in a collection
- How to get all records within the last Two Days from the current Date using EF 4?
- How do you get the properties, operators and values from an Expression<Func<T, bool>> predicate?
- Using LINQ to get the results from another LINQ collection
- How can I write the following code more elegantly using LINQ query syntax?
- How can I code an outer join using LINQ and EF6?
- How to get leaf node from a nested collection using lambda expression
- How do I get the most recent entry from a table using LINQ?
- How to get strongly-typed collection from XML using Linq
- How do I get the Nth largest element from a list with duplicates, using LINQ?
- How to get the exact child element with corresponding parent only from multilevel embedded MongoDB document using C#
- How can I get the Max id of a table or 1 if empty using Linq?
More Query from same tag
- Error creating DataBase with Linq to SQL
- Mapping a bool to a 'Y'/'N' field in a LINQ to SQL datasource
- Problems with casting LinQ result to strongly typed collection
- Mapping two lists of points and replace with linq
- How can i use LINQ to pass highlighted Cells to another DataGridView?
- Remove multi indexes from linq list
- Linq query in a Complex Dictionary
- Problems adding nodes
- Linq Aggregate on object and List
- Do I need to use MultipleActiveResultSets feautre?
- List.FindAll don't returns a result set
- Trying to map two properties together, getting error "LINQ to Entities does not recognize the method 'System.String ToString()' method"
- How do I combine multiple linq queries into one results set?
- Linq vs MS Enterprise Library DAAB
- Create conditional WHERE clause on joined table in Linq and EF
- FIFO inventory systems - Converting T-SQL to Linq
- List.Contains returns incorrect result but List.Exists works
- Why Linq to postgresql use tolower appear "IS Null"
- Ranking. Linq to sql question
- Is there an equivalent of "None()" in LINQ?
- Search records with code pattern in column value c#
- How to recursively call Where clause in Linq or SQL
- Linq Query return a Concat of Dates to String?
- Group by and average in linq
- Dynamic LINQ API with .NET Framework 4
- What is the best way to write a two column query in LINQ to Entity 6? And save the results to two different variables?
- How to compound Expressions of similar types?
- Entity Framework upgrade to 6.2.0 from 6.1.x breaks certain queries unless I enable MARS
- LINQPad access SqlOutputWriter from custome library
- How to get all the birthdays of today?