C# Program to Check all Items of a Float Array is Greater than 5.0 using LINQ
Given a float array, now our task is to check if all the elements present in the float array are greater than 5.0. So we use the All() method of LINQ. This method is used to check if all the elements in the given sequence satisfy the given condition. It will return true if all the elements of the specified sequence pass the test in the given predicate, otherwise, it will return false. So to solve the given problem we use the following query:
result = nums.All(element => element > 5.0F);
Here, the result is a boolean type variable that stores the final result, nums is the array of float, and the All() method contains the condition which checks each element present in the given array satisfy the condition or not. Here if all the elements of the array fulfill the given condition then this statement “nums.All(element => element > 5.0F)” will return true. If any of the elements does not fulfill the given condition then it will return false.
Input : [6.0, 7.89, 8.9, 89.5, 13.3] Output : true Input : [2.0, 1.89, 2.9, 89.5, 13.3] Output : false
Elements in the array are not greater than 5
Is nums1 contain all the elements greater than 5.0f: False Is nums2 contain all the elements greater than 5.0f: True