C# and LINQ – Finding all the elements of an integer array less than 35

Published on November 12, 2016 by abundantcode

Filed under C#

Last modified November 12, 2016

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 499 times

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

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment


x

You might be Interested in these Posts

VB.NET and LINQ – Filter elements from object collection with Logical Operators

Here’s a sample code snippet demonstrating how to filter elements from a list of objects using the w...

C# and LINQ – Filter elements from object collection with Logical Operators

Here’s a sample code snippet demonstrating how to filter elements from a list of objects using the w...

VB.NET and LINQ – Filter elements from object collection using where clause

Here’s a sample code snippet demonstrating how to filter elements from a list of objects using the w...