LINQ - Second Maximum value - Asked By Bichel A on 20-Jun-11 11:40 AM

Hi
How to write Linq Query to find 2nd Maximum value in a array of integers.

Thanks
Riley K replied to Bichel A on 20-Jun-11 11:50 AM
You can use this below statement

int secondHighest = (from number in numbers
           orderby number descending
           select number).Skip(1).First();
Skip is used to skip the element with the given index

Thanks
Kirtan Patel replied to Bichel A on 20-Jun-11 11:53 AM
here is how to write such query

var employee = Employees
  .OrderByDescending(e => e.Salary)
  .Skip(1)
  .First();
thanks
Asked By Bichel A on 20-Jun-11 11:55 AM
Thank You ,Its working
Can u tell me how to find 2nd minimum value in the array?

Asked By Bichel A on 20-Jun-11 11:56 AM
Thank You ,Its working
Can u tell me how to find 2nd minimum value in the array?