This is my list:
List<int> numbers=new List<int> { 12, 5, -8, 4, 7, 28, 3, 22 };
How can I get 4 maximum numbers by lambda: I need these ones: {28, 22, 12, 7}
Use:
var result = numbers.OrderByDescending(n => n).Take(4);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With