C# Queryable Union 方法


使用 Queryable Union 方法对两个序列执行 Union。

以下是我们的数组。

int[] arr1 = { 29, 40, 15, 55, 70, 30, 90 };
int[] arr2 = { 30, 36, 40, 18, 15, 55, 75 };

现在,使用 Union 方法获取数组的 Union。

arr1.AsQueryable().Union(arr2);

示例

 现场演示

using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
   public static void Main() {
      int[] arr1 = { 29, 40, 15, 55, 70, 30, 90 };
      int[] arr2 = { 30, 36, 40, 18, 15, 55, 75 };
      IEnumerable<int> res = arr1.AsQueryable().Union(arr2);
      foreach (int a in res)
      Console.WriteLine("{0} ", a);
   }
}

产出

29
40
15
55
70
30
90
36
18
75

更新于: 2020 年 6 月 23 日

161 次浏览

开启您的 职业生涯

通过完成课程获得认证

开始课程
广告
© . All rights reserved.