LINQ help
I have a collection of ints, how can I take the last three that are bigger than 100?
is there a better way than this?
is there a better way than this?
using System;
using System.Linq;
class Program
{
static void Main()
{
int[] numbers = { 80, 120, 110, 90, 10, 140, 150, 50, 22, -800 };
var result = numbers.Where(num => num > 100).Reverse().Take(3).Reverse().ToArray();
Console.WriteLine("Last 3 elements over 100:");
foreach (var num in result)
{
Console.WriteLine(num);
}
}
}