Efficiently merge string arrays in .NET, keeping distinct values

前端 未结 6 1615
迷失自我
迷失自我 2021-02-02 06:38

I\'m using .NET 3.5. I have two string arrays, which may share one or more values:

string[] list1 = new string[] { \"apple\", \"orange\", \"banana\" };
string[]         


        
6条回答
  •  不思量自难忘°
    2021-02-02 07:03

    string[] result = list1.Union(list2).ToArray();
    

    from msdn: "This method excludes duplicates from the return set. This is different behavior to the Concat(TSource) method, which returns all the elements in the input sequences including duplicates."

提交回复
热议问题