static Array Matrix(int Rows, int Columns)
{
int[,] Lottery = new int[Rows,Columns];
for (int i = 0; i < Lottery.GetLength(0); i++)
{
for (int j = 0; j < Lottery.GetLength(1); j++)
{
Lottery[i, j] = RandomNum(1, 46);
Console.Write("{0,3},", Lottery[i, j]);
Console.WriteLine();
}
return Lottery;
}
}
I have this function to initiate and print a matrix, and I want to do a foreach loop that checks all the numbers in each row, but when I do foreach (int i in Matrix), it tells me that I cannot operate on a method group, and when I do foreach (int i in Lottery), it tells me that Lottery is a namespace.
I'm a beginner and I don't know what to do.
foreach (int i in Matrix)is incorrect because you should invoke Matrix method with 2 parameters; tryforeach (int i in Matrix(3,4))int[]like this:private static int[,] Matrix(int Rows, int Columns)static int[,] Matrix(int Rows, int Columns); it will be type-safe and will allow to use the same nestedforloops with result of method