C#实现合并两个数组并除去相同元素

int[] Array_Heavy(int[] arr1,int[] arr2)
    {
        Dictionary<int, bool> temp1 = new Dictionary<int, bool>();
        List<int> temp2 = new List<int>();
        for (int i = 0; i < arr2.Length; i++)
        {
            if (!temp1.ContainsKey(arr2[i]))
            {
                temp1.Add(arr2[i], true);
            }
           
        }

        for (int i = 0; i < arr1.Length; i++)
        {
            if (!temp1.ContainsKey(arr1[i]))
            {
                temp2.Add(arr1[i]);
            }
        }

        return Array_Heavy(arr2,arr1,temp2);
    }
    int[] Array_Heavy(int[] arr1,int[] arr2,List<int> list)
    {
        Dictionary<int, bool> temp1 = new Dictionary<int, bool>();

        for (int i = 0; i < arr2.Length; i++)
        {
            if (!temp1.ContainsKey(arr2[i]))
            {
                temp1.Add(arr2[i], true);
            }
        }

        for (int i = 0; i < arr1.Length; i++)
        {
            if (!temp1.ContainsKey(arr1[i]))
            {
                list.Add(arr1[i]);
            }
        }
        return list.ToArray();
    }

 

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 1024 设计师:上身试试 返回首页