CSharp · Console
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApplication1
{
public class Program
{
public static void Main()
{
var rnd = new Random();
var collection = Enumerable
.Range(1, 100)
.Select(_ => new Item(rnd.Next(30)))
.ToList();
var filteredCollection = collection.OrderByDescending(r => r.Prop).Take(5);
foreach (var item in filteredCollection)
{
Console.WriteLine(item.Prop);
}
}
}
public class Item
{
public int Prop { get; set; }
public Item(int prop)
{
Prop = prop;
}
}
}