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);
// getting elements above 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