C# - Check all items of a float array are greater than 5.0 using LINQ

Learn, how to check all items of a float array is greater than 5.0 using Linq in C#? By Nidhi Last updated : April 01, 2023

Here, we will create an array of float numbers and then check all items of the array are greater than 5.0 using Linq All() method.

C# program to check all items of a float array is greater than 5.0 using LINQ

The source code to check all items of a float array is greater than 5.0 using Linq, is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to check all items of a float array 
//is greater than 5.0 using Linq.

using System;
using System.Linq;

class LinqDemo
{
    static void Main(string[] args)
    {
        float[] numbers = { 8.2F, 11.2F, 7.6F, 8.3F, 5.5F,6.4F };

        bool isgreater = false;
        
        isgreater = numbers.All(x => x > 5.0F);
        
        Console.WriteLine("All floating pointer is greater the 5.0? --> " + isgreater);
    }
}

Output

All floating pointer is greater the 5.0? --> True
Press any key to continue . . .

Explanation

In the above program, we created a LinqDemo that contains the Main() method. In the Main() method we created an array of float numbers.

isgreater = numbers.All(x => x > 5.0F);

The above code will return a boolean value, where we check all elements of the array are greater than 5.0 if any one of them is less than 5.0 then All() method will return false otherwise it will return true.

C# LINQ Programs »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.