C# 任意方法
Any 方法检查序列中是否存在满足特定条件的任何元素。
如果任何元素满足条件,则返回 true。
让我们看一个例子。
int[] arr = {5, 7, 10, 12, 15, 18, 20};现在,我们将使用 Any() 方法检查上述数组中是否存在任何元素大于 10。
arr.AsQueryable().All(val => val > 5);
如果任何元素满足条件,则返回 True。
让我们看完整的例子。
示例
using System;
using System.Linq;
class Demo {
static void Main() {
int[] arr = {5, 7, 10, 12, 15, 18, 20};
// checking if any of the array elements are greater than 10
bool res = arr.AsQueryable().Any(val => val > 10);
Console.WriteLine(res);
}
}输出
True
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP