comparing contents of 2 arrays

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Mar 2008
Posts: 63
Reputation: 666kennedy is an unknown quantity at this point 
Solved Threads: 0
666kennedy 666kennedy is offline Offline
Junior Poster in Training

comparing contents of 2 arrays

 
0
  #1
Aug 13th, 2009
i have 2 arrays

controllerlist[11] and taglist[5]

i need to compare them so that i can find any elements that match, is there a way of doing it instead of nested for loops?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,046
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 309
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Postaholic

Re: comparing contents of 2 arrays

 
0
  #2
Aug 13th, 2009
perhaps you could do it with one for less by using the Contains method:
  1. int[] a = new int[4] { 1, 2, 3, 4 };
  2. int[] b = new int[3] { 5, 6, 3 };
  3. bool c = a.Contains(b[2]);
The boolean c should be true here because b[2]=3 and a contains 3.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: comparing contents of 2 arrays

 
0
  #3
Aug 13th, 2009
Sort them individually, then with one loop interleave them while comparing them for matches.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 316 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC