实现该要求,首先想到的应该是:使用数组循环遍历。
本文分享下用Linq处理该问题的代码.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ExampleDemo
{
class Program
{
static void Main(string[] args)
{
int[] arr1 = new int[] { 1, 2, 3 };
int[] arr2 = new int[] { 4, 5, 1, 7 };
//使用Union将数组一和数组二不相同的结果并上数组二和数组一不相同的结果。最后进行一次排序。
var arr = (from a in arr2
where
arr1.Contains(a) == false
select a).Union(from b in arr1