배열을 설정합니다.
int[] arr = { 40, 42, 12, 83, 75, 40, 95 }; Where 절과 술어를 사용하여 50개 이상의 요소를 가져옵니다.
IEnumerable<int> myQuery = arr.AsQueryable() .Where((a, index) => a >= 50);
전체 코드를 보자 -
예
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
int[] arr = { 40, 42, 12, 83, 75, 40, 95 };
Console.WriteLine("Array:");
foreach (int a in arr) {
Console.WriteLine(a);
}
// getting elements above 70
IEnumerable<int> myQuery = arr.AsQueryable() .Where((a, index) => a >= 50);
Console.WriteLine("Elements above 50...:");
foreach (int res in myQuery) {
Console.WriteLine(res);
}
}
} 출력
Array: 40 42 12 83 75 40 95 Elements above 50...: 83 75 95