programmer
programmer

Reputation: 83

Get top max item by linq

consider:

public class student
{
public int Avd{get;set;}
}

and in main :

list<student> Students =new List<student>{2,3,6,1,20,12,45};

I want get top 5 max AVG in Students by linq . how can i do this?

Upvotes: 0

Views: 290

Answers (2)

Milen
Milen

Reputation: 8867

Students = Students.OrderByDescending(x=>x.Avd).Take(5).ToList();

Upvotes: 1

Selman Gen&#231;
Selman Gen&#231;

Reputation: 101681

Sort the list based on Avg in descending order then use Take to get 5 students:

Students.OrderByDescending(s => s.Avg).Take(5);

Upvotes: 0

Related Questions