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

Here, we are going to learn how to check all items of a float array is greater than 5.0 using Linq in C#?
Submitted by Nidhi, on August 31, 2020

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.

Program:

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 »


ADVERTISEMENT
ADVERTISEMENT




Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.