Thực hiện Union (hợp) trên hai chuỗi sử dụng phương thức Queryable Union.
Đây là các mảng của chúng ta.
int[] arr1 = { 29, 40, 15, 55, 70, 30, 90 };
int[] arr2 = { 30, 36, 40, 18, 15, 55, 75 };
Bây giờ, lấy Union của các mảng dùng phương thức Union.
arr1.AsQueryable().Union(arr2);
Ví dụ
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);
}
}
Kết quả
29 40 15 55 70 30 90 36 18 75