Click here to Skip to main content
15,889,499 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi people
there is this method which i cannot get what it is doing




C#
bool IsPass()
      {
          for (int i = 0; i < 7; i++)
          {
              for (int j = 0; j < 7; j++)
              {
                  if (GenerateArray.a[i, j] != Resource.arr1[i, j]) return false ;
              }
          }
          return true;
      }



the main line i'm confused with is

C#
if (GenerateArray.a[i, j] != Resource.arr1[i, j]) return false ;
            }
        }
        return true;
    }



here generatearray and resouce are method
i can't actually understand what [i,j] will do and why return false and return true are written
please help
Posted

It is a comparison of values in two multi-dimensional arrays.
http://msdn.microsoft.com/en-us/library/2yd9wwz4.aspx[^]


C#
if (GenerateArray.a[i, j] != Resource.arr1[i, j]) 
  return false ;


So if the value in cell [i, j] for matrix GenerateArray.a is different from cell [i,j] in Resource.arr1 the method returns false.
 
Share this answer
 
Comments
[no name] 6-Jul-14 1:42am    
do you mean to say that i and j represent row and column of the array??
if yes then does i and j represent row and column respectively??
You better read about Multidimensional arrays and how to iterate over items of Multidimensional arrays.
check
Multidimensional Arrays (C# Programming Guide)[^]
C# 2D Array[^]

here GenerateArray.a and Resource.arr1 are 2D arrays and you are iterating over the items and comparing them.
below line compare same item in both arrays.
C#
GenerateArray.a[i, j] != Resource.arr1[i, j]

if above condition not satisfied then you found one item which not machining and return false and exist the method.
if all items are machining then your program will come to the return true line and exist the method with return value as true
 
Share this answer
 
You are simply comparing the items in the two arrays, if all items in one array matches to the all items in the second array, returns true, otherwise false.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900