Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Assuming we have a list of employees with properties "Name" and "Salary", the LINQ query to retrieve the employee with the second highest salary would be:

var secondHighestSalaryEmployee = employees.OrderByDescending(e => e.Salary).Skip(1).FirstOrDefault();

This query first sorts the employees in descending order by their salary, then skips the first employee (i.e. the one with the highest salary), and finally selects the first employee from the remaining list (i.e. the one with the second highest salary).