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 次瀏覽

開啟您的 職業生涯

透過完成課程獲得認證

開始課程
廣告