Computer >> Máy Tính >  >> Lập trình >> C#

Phương thức TrueForAll () trong Mảng C #

Với phương thức TrueForAll () trong mảng, bạn có thể kiểm tra mọi phần tử cho một điều kiện.

Hãy để chúng tôi xem một ví dụ -

Ví dụ

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);
   }
}

Đầu ra

True

Với phương thức TrueForAll () trong mảng, bạn có thể kiểm tra mọi phần tử cho một điều kiện.

Hãy để chúng tôi xem một ví dụ -

Ví dụ

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);
   }
}

Đầu ra

True