C# and Lambda – 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 2119 times

Here’s a sample code snippet demonstrating how to find all the elements of an integer array that is less than 35 using Lambda expression in C#.

The Where keyword in C# is used to filter the elements from a collection based on the specified criteria.

How to find all the elements of an integer array less than 35 using Lambda expression 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 };
            // find all the numbers greater than 35 using Lambda
            var output = input.Where(a => a > 35);
            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 Comment


x

You might be Interested in these Posts

How to download a file from a URL using C#?

You can use the WebClient class in C# to download a file. How to download a file from a URL using C...

How to Create an Empty array without defining the size in C# ?

When we create an array in C# , we tend to define the size of the array as shown below. String[] st...

C Program to convert decimal number to binary

Problem Write a program in C to convert a decimal number to binary number How to convert a decimal...