Here’s a sample code snippet demonstrating how to find all the elements of an integer array that is less than 35 using LINQ in C#.
The where keyword in C# is used to filter the elements from a collection based on the specified criteria. Ensure that you import the System.Linq namespace to your C# code.
How to find all the elements of an integer array less than 35 using LINQ in C# ?
using System.Diagnostics; using System.Linq; namespace AbundantcodeCsharpSample { class Program { static void Main(string[] args) { int[] input = { 78,5,23,67,11,23 }; // LINQ Query to find all the numbers greater than 35 var output = from m in input where m > 35 select m; Debug.WriteLine("Numbers Greater than 35"); foreach (var item in output) Debug.WriteLine(item); } } }
The output of the program is
Numbers Greater than 35
78
67
Leave a Reply