使用Except()方法获得两个数组之间的差。
以下是两个数组。
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