用於返回兩個序列之間的差別的 C# 程式
設定兩個序列。
double[] arr1 = { 10.2, 15.6, 23.3, 30.5, 50.2 };
double[] arr2 = { 15.6, 30.5, 50.2 };要獲取上述兩個陣列之間的差異,請使用 Except() 方法。
IEnumerable<double> res = arr1.AsQueryable().Except(arr2);
以下為程式碼。
示例
using System;
using System.Linq;
using System.Collections.Generic;
class Demo {
static void Main() {
double[] arr1 = { 10.2, 15.6, 23.3, 30.5, 50.2 };
double[] arr2 = { 15.6, 30.5, 50.2 };
Console.WriteLine("Initial List...");
foreach(double ele in arr1) {
Console.WriteLine(ele);
}
IEnumerable<double> res = arr1.AsQueryable().Except(arr2);
Console.WriteLine("New List...");
foreach (double a in res) {
Console.WriteLine(a);
}
}
}輸出
Initial List... 10.2 15.6 23.3 30.5 50.2 New List... 10.2 23.3
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP