TrueForAll() 方法在 C# 陣列中


使用陣列中的 TrueForAll() 方法,你可以根據條件檢查每個元素。

讓我們看一個示例 −

示例

 線上演示

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

輸出

True

使用陣列中的 TrueForAll() 方法,你可以根據條件檢查每個元素。

讓我們看一個示例 −

示例

 線上演示

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

輸出

True

更新於: 2020 年 6 月 22 日

113 次瀏覽

開啟你的 職業

完成課程得到認證

開始吧
廣告
© . All rights reserved.