Monday, 18 August 2014

Program To Find a Fifth Highest Salary Using LINQ

In this Program i would like to explore a To Find a Fifth Highest Salary Using LINQ.






Program:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Linq
{
    class Sal
    {
        static void Main(string[] args)
        {
            List<int> a = new List<int>() { 10, 20, 30, 40, 50, 40, 60, 70, 70, 80, 90, 80 };
            int max = (from p in a select p).Max();
            Console.WriteLine("Maximum Salary is:"+max);                    
            var fhs = a.ToList().OrderBy(ppp => ppp).Skip(5).First();
            Console.WriteLine("Fifth Highest Salary is:"+fhs);
            Console.ReadLine();
        }
    }
}




Output:

LINQ Example
Liq Example

No comments :

Post a Comment