943,531 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 1052
  • C# RSS
Aug 13th, 2009
0

comparing contents of 2 arrays

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
666kennedy is offline Offline
63 posts
since Mar 2008
Aug 13th, 2009
0

Re: comparing contents of 2 arrays

perhaps you could do it with one for less by using the Contains method:
C# Syntax (Toggle Plain Text)
  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.
Reputation Points: 2023
Solved Threads: 644
Senior Poster
ddanbe is offline Offline
3,735 posts
since Oct 2008
Aug 13th, 2009
0

Re: comparing contents of 2 arrays

Sort them individually, then with one loop interleave them while comparing them for matches.
Reputation Points: 546
Solved Threads: 99
Practically a Posting Shark
wildgoose is offline Offline
891 posts
since Jun 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Time in C#
Next Thread in C# Forum Timeline: Updating a sql checkbox





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC