Ok, I'm trying to search a two dimensional array using the Length property (I have to use this otherwise I'd just use GetLength() ). This array is randomly populated with a set number of rows and columns. It will ask the user for a number to search for and then it will search the array and return true or false AND send back the indexes of the row and column if that number is found.
I'm fairly confident in the code from the research I've done to get the for loop set properly, but currently I'm getting an error that says "Wrong number of indices inside []; expected 2" when I try to search the columns of the array.
I've looked this error up and from what I've found this should be the right setup. So, I'm not sure where my issue is with this loop, could someone take a look at let me know what step I'm missing?
Thanks!
int [,] math;
math = new int[3, 5]; //So you can see my array that is declared in main
static bool SearchArray(int search, int [,] array, out int row, out int coln)
{
row = -1;
coln = -1;
// search parameter is given from another method where it asks the user for a number to search for in the array.
for (int x = 0; x < array.Length; x++)
{
for (int y = 0; y < array[x].Length; y++) //error is here with the array[x] and continues to any reference I try to make similarly.
{
if (array[x][y] == search)
{
row = array[x];
coln = array[y];
return true;
}
}
}
return false