C# All method



The All Method checks for all the values in a collection and returns a Boolean. Even if one of the element do not satisfy the set condition, the All() method returns False.

Let us see an example −

int[] arr = {10, 15, 20};

Now, using All() method, we will check whether each element in the above array is greater than 5 or not.

arr.AsQueryable().All(val => val > 5);

Example

 Live Demo

using System;
using System.Linq;
class Demo {
   static void Main() {
      int[] arr = {10, 15, 20};
      // checking if all the array elements are greater than 5
      bool res = arr.AsQueryable().All(val => val > 5);
      Console.WriteLine(res);
   }
}

Output

True
Updated on: 2020-06-22T15:43:53+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements