I'm trying to put numbers on a 2d array by Randomizing the numbers. this is what i got so far but i keep getting 15 and i want it to go through each element in the array not one.
static Random random = new Random();
static void Main(string[] args)
{
int[,] array = new int[3, 5];
FillArray(array);
PrintArray(array);
}
public static void FillArray(int [ , ] arr)
{
for (int c = 0; c < arr.GetLength(1); c++)
{
for (int r = 0; r < arr.GetLength(0); r++)
{
arr[r, c] = random.Next(15, 96);
}
}
}
public static void PrintArray(int [,] arr)
{
WriteLine(arr.Length);
}
WriteLine(arr.Length);does? Please read How to Ask and take the tourLengthof the array is 15. That's why you see 15. If you want to print each element in an array, you have to write code to print each element in an array.