I want to find out 2nd highest or nth highest salary using linq....
List<Employee> employees = new List<Employee>()
{
new Employee { Id = 1, UserName = "Anil" , Salary = 5000},
new Employee { Id = 2, UserName = "Sunil" , Salary = 6000},
new Employee { Id = 3, UserName = "Lokesh" , Salary = 5500},
new Employee { Id = 4, UserName = "Vinay" , Salary = 7000},
new Employee { Id = 5, UserName = "Vijay" , Salary = 6000},
new Employee { Id = 6, UserName = "vikas" , Salary = 6000}
};
var result = employees.OrderByDescending(x => x.Salary).Select(x => x.Salary).Skip(1).Take(3 - 1).FirstOrDefault();
but return only one reocrd from this query.the actual result is return 3 records.
I am also try using tolist().
help me......