using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LInqQuery
{
class emp
{
public decimal Salary { get; set; }
}
class Program
{
static List<emp> empDetails = new List<emp>();
static void Main(string[] args)
{
empDetails.Add(new emp {Salary=1000 });
empDetails.Add(new emp { Salary = 500 });
empDetails.Add(new emp { Salary = 500 });
empDetails.Add(new emp { Salary = 3000 });
empDetails.Add(new emp { Salary = 2000 } );
var empResult = (from e in empDetails
orderby e.Salary descending
select e).Skip(1).First();
Console.WriteLine("Second highest salary");
Console.WriteLine(empResult.Salary);
var empResult1 = empDetails
.OrderByDescending(x => x.Salary)
.Select(x => x.Salary)
.Skip(1)
.First();
Console.WriteLine("Second highest salary");
Console.WriteLine(empResult1);
var empResult2 = (from e in empDetails
group e by e.Salary into tmp
orderby tmp.Key descending
select tmp.Key).Skip(2).First();
Console.WriteLine("Third highest salary");
Console.WriteLine(empResult2);
var empResult3 = empDetails
.GroupBy(x => x.Salary)
.OrderByDescending(g => g.Key)
.Select(g => g.Key)
.Skip(2)
.First();
Console.WriteLine("Third highest salary");
Console.WriteLine(empResult3);
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LInqQuery
{
class emp
{
public decimal Salary { get; set; }
}
class Program
{
static List<emp> empDetails = new List<emp>();
static void Main(string[] args)
{
empDetails.Add(new emp {Salary=1000 });
empDetails.Add(new emp { Salary = 500 });
empDetails.Add(new emp { Salary = 500 });
empDetails.Add(new emp { Salary = 3000 });
empDetails.Add(new emp { Salary = 2000 } );
var empResult = (from e in empDetails
orderby e.Salary descending
select e).Skip(1).First();
Console.WriteLine("Second highest salary");
Console.WriteLine(empResult.Salary);
var empResult1 = empDetails
.OrderByDescending(x => x.Salary)
.Select(x => x.Salary)
.Skip(1)
.First();
Console.WriteLine("Second highest salary");
Console.WriteLine(empResult1);
var empResult2 = (from e in empDetails
group e by e.Salary into tmp
orderby tmp.Key descending
select tmp.Key).Skip(2).First();
Console.WriteLine("Third highest salary");
Console.WriteLine(empResult2);
var empResult3 = empDetails
.GroupBy(x => x.Salary)
.OrderByDescending(g => g.Key)
.Select(g => g.Key)
.Skip(2)
.First();
Console.WriteLine("Third highest salary");
Console.WriteLine(empResult3);
Console.ReadLine();
}
}
}
No comments:
Post a Comment