TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Maharudra Gadekar
1.4k
367
82.1k
How to find out 2nd or nth highest salary?
Feb 27 2020 1:09 AM
Dear All,
I want to find out 2nd highest or nth highest salary using linq....
bellow is my tried code:
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}
};
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
Reply
Answers (
8
)
Add where clause in LINQ query
Filter joined string array