用于返回两个序列之间的差别的 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