C#程序,用于检查序列中的元素是否满足条件
使用All()方法检查序列中的元素是否满足条件。即使其中一个元素不满足设置条件,All()方法也会返回False。
要设置条件,请使用Lambda表达式。下面显示了检查所有元素是否大于20的条件。
myArr.AsQueryable().All(val => val > 20);
让我们来看一个例子。
示例
using System;
using System.Linq;
class Demo {
static void Main() {
int[] myArr = {7, 15, 22, 30, 40};
// checking if all the array elements are greater than 20
bool res = myArr.AsQueryable().All(val => val > 20);
Console.WriteLine(res);
}
}输出结果
False
热门推荐
1 训练狗狗工作
4 狗狗定点排便训练
5 狗狗训练吠叫
6 狗狗尿垫训练
7 狗狗训练座
8 狗狗训练攻略
9 狗狗训练记
10 做训练狗狗
11 狗狗训练词
12 狗狗谢谢怎么训练
13 狗狗训练如厕
14 狗狗太凶怎么训练
15 狗狗训练它
16 狗狗克制训练
17 训练基地狗狗
18 怎么样训练狗狗大小硬