We help IT Professionals succeed at work.

Comparing two string arrays and removing duplicates

EMThomas asked
Last Modified: 2010-04-21
I have tried a bit back and forth but can't find an easy, fast and reliable way of solving my problem (nor one that works). I was hoping someone out there might have tackled this themselves earlier, and perhaps had a code example they would share. The problem is as follows;

I have two string arrays, and I want to run them through a function that returns a new array. The new array is a combination of the two, but with duplicates removed.
Watch Question

Mihai StancescuSoftware Engineer
This one is on us!
(Get your first solution completely free - no credit card required)

How much strings do you expect in your arrays.
If speed matters then I would recommend following:

sort your arrays first. Then your can iterate through both arrays and easy compare the strings.


I currently use arrays as follows;
string[] array = new string[1000];
Would it be possible to rewrite that function to work with arrays of a certain variable type?


Pacman: I'm expecting about 700-800 short strings in each array, but I will have to run it several times for each keypress (realtime search as user types).
Software Architect
Top Expert 2008
This one is on us!
(Get your first solution completely free - no credit card required)
Mihai StancescuSoftware Engineer

If you are asking me, about my function the answer is yeah because you have Array.GetValue() method.



You guys are amazing, thank you very much!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.