Medium csharp

Select top 3 salaries

Problem

Get top 3 salaries from list using LINQ.

Hints
  • OrderByDescending then Take(3)

Your practice code

Ready — edit the code above and click Run.

Solution

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.

Explanation

OrderByDescending + Take(3)—deferred execution until enumeration.

Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details