Efficiently merge string arrays in .NET, keeping distinct values

前端 未结 6 1616
迷失自我
迷失自我 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:02

    You don't know which approach is faster until you measure it. The LINQ way is elegant and easy to understand.

    Another way is to implement an set as an hash array (Dictionary) and add all the elements of both the arrays to the set. Then use set.Keys.ToArray() method to create the resulting array.

提交回复
热议问题