예외() 메서드를 사용하여 두 배열의 차이를 가져옵니다.
다음은 두 개의 배열입니다.
int[] arr = { 9, 12, 15, 20, 35, 40, 55, 67, 88, 92 };
int[] arr2 = { 20, 35 }; 차이를 얻으려면 두 번째 목록의 요소를 제외하고 첫 번째 목록을 반환하는 except() 메서드를 사용하십시오.
arr.AsQueryable().Except(arr2);
다음은 전체 예입니다.
예
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main() {
int[] arr = { 5, 10, 15, 20, 35, 40 };
int[] except = { 20, 35 };
Console.WriteLine("Initial List...");
foreach(int ele in arr)
Console.WriteLine(ele);
IEnumerable<int> res = arr.AsQueryable().Except(except);
Console.WriteLine("New List...");
foreach (int a in res)
Console.WriteLine(a);
}
} 출력
Initial List... 5 10 15 20 35 40 New List... 5 10 15 40