TrueForAll() method in C# Arrays

CsharpProgrammingServer Side Programming

With TrueForAll() method in arrays, you can check every element for a condition.

Let us see an example −

Example

 Live Demo

using System;
using System.Text;
public class Demo {
   public static void Main() {
      int[] val = { 97, 45, 76, 21, 89, 45 };
      // checking whether all the array element are more than one or not
      bool result = Array.TrueForAll(val, res => res > 1);
      Console.WriteLine(result);
   }
}

Output

True

With TrueForAll() method in arrays, you can check every element for a condition.

Let us see an example −

Example

 Live Demo

using System;
using System.Text;
public class Demo {
   public static void Main() {
      int[] val = { 97, 45, 76, 21, 89, 45 };
      // checking whether all the array element are more than one or not
      bool result = Array.TrueForAll(val, res => res > 1);
      Console.WriteLine(result);
   }
}

Output

True
raja
Published on 04-Sep-2018 15:53:51
Advertisements