C# All method

ProgrammingServer Side ProgrammingCsharp

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
raja
Published on 11-Sep-2018 12:48:36
Advertisements