Click here to Skip to main content
15,883,996 members

Response to: array check and comparison

Revision 2
As far as the arrays are not too long and that the type of data can be compared with == operator

You can use two for loops one nested into the another one. Actually the same operation than going through a 2-dimensional array[i][j]

C#
bool error = false;
for (int i=0; i < length_a; i++)
{
   for (int j=0; j < length_b; j++)
   {
      if (array_a[i]==array[b])
      {
         error = true;
         break;
      }
   }
}

if (error == false)
{
   // No match found, do whatever you need to
}
Posted 19-Nov-12 5:26am by Nelek.
Tags: