Dear All,
I want to find out 2nd highest or nth highest salary using linq....
bellow is my tried code:
List employees = new List()
{
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}
};
Linq Query:
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......
thanks in advance


Navaneeth KrishnanRank #1,172 · 1.5K reputationPosted Feb 26, 2020, 8:42 PM EST
Siddharth GajbhiyeRank #376 · 6.7K reputationPosted Feb 26, 2020, 9:10 PM EST
Amit MohantyRank #112 · 20K reputationPosted Feb 26, 2020, 9:11 PM EST
Amit MohantyRank #112 · 20K reputationPosted Feb 26, 2020, 10:14 PM EST
Ravi PatelRank #439 · 5.7K reputationPosted Feb 26, 2020, 10:32 PM EST
Amit MohantyRank #112 · 20K reputationPosted Feb 26, 2020, 10:40 PM EST
Maharudra GadekarRank #5,163 · 309 reputationPosted Feb 26, 2020, 10:06 PM EST
Maharudra GadekarRank #5,163 · 309 reputationPosted Feb 26, 2020, 10:07 PM EST