Where方法根据谓词过滤值数组。
在这里,谓词正在检查70以上的元素。
Where((n, index) => n >= 70);
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
int[] arr = { 10, 30, 20, 15, 90, 85, 40, 75 };
Console.WriteLine("Array:");
foreach (int a in arr)
Console.WriteLine(a);
//获得高于70的元素
IEnumerable myQuery = arr.AsQueryable().Where((n, index) => n >= 70);
Console.WriteLine("Elements above 70...:");
foreach (int res in myQuery)
Console.WriteLine(res);
}
}输出结果
Array: 10 30 20 15 90 85 40 75 Elements above 70...: 90 85 75