C# 可查询联合方法
csharpprogrammingserver side programming
使用可查询联合方法对两个序列执行联合。
以下是我们的数组。
int[] arr1 = { 29, 40, 15, 55, 70, 30, 90 }; int[] arr2 = { 30, 36, 40, 18, 15, 55, 75 };
现在,使用 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