รับความแตกต่างระหว่างสองอาร์เรย์โดยใช้วิธี Exception()
ต่อไปนี้เป็นสองอาร์เรย์
int[] arr = { 9, 12, 15, 20, 35, 40, 55, 67, 88, 92 };
int[] arr2 = { 20, 35 }; หากต้องการทราบความแตกต่าง ให้ใช้วิธี Exception() ที่คืนค่ารายการแรก ยกเว้นองค์ประกอบในรายการที่สอง
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