Get top 3 salaries from list using LINQ.
Ready — edit the code above and click Run.
using System;
using System.Linq;
class Program
{
static void Main()
{
int[] salaries = { 45000, 120000, 75000, 98000, 150000, 62000 };
var top3 = salaries.OrderByDescending(s => s).Take(3);
Console.WriteLine(string.Join(", ", top3));
}
}
Try solving on your own first, then reveal the official answer.
OrderByDescending + Take(3)—deferred execution until enumeration.