0
0
C Sharp (C#)programming~20 mins

Multi-dimensional arrays in C Sharp (C#) - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Multi-dimensional Arrays Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a 2D array element access
What is the output of this C# code snippet?
C Sharp (C#)
int[,] matrix = { {1, 2, 3}, {4, 5, 6} };
Console.WriteLine(matrix[1, 2]);
ARuntime error
B5
C3
D6
Attempts:
2 left
💡 Hint
Remember that the first index is the row and the second is the column.
Predict Output
intermediate
2:00remaining
Length properties of a 3D array
Given the following 3D array, what is the output of the code below?
C Sharp (C#)
int[,,] cube = new int[2,3,4];
Console.WriteLine(cube.GetLength(1));
A3
B2
C4
DRuntime error
Attempts:
2 left
💡 Hint
GetLength(n) returns the size of the dimension n, starting from 0.
🔧 Debug
advanced
2:00remaining
Identify the error in multi-dimensional array initialization
What error will this code produce when compiled or run?
C Sharp (C#)
int[,] grid = new int[2, 2] { {1, 2}, {3, 4}, {5, 6} };
ACompile-time error: Too many initializers for the array
BRuntime error: Index out of range
CNo error, compiles and runs fine
DCompile-time error: Missing semicolon
Attempts:
2 left
💡 Hint
Check the declared size versus the number of initializer rows.
Predict Output
advanced
2:00remaining
Output of nested loops over a 2D array
What will be printed by this code?
C Sharp (C#)
int[,] arr = { {1, 2}, {3, 4} };
for (int i = 0; i < arr.GetLength(0); i++)
{
    for (int j = 0; j < arr.GetLength(1); j++)
    {
        Console.Write(arr[i, j] + " ");
    }
    Console.WriteLine();
}
A1 3 \n2 4 \n
B1 2 3 4 \n
C1 2 \n3 4 \n
DRuntime error
Attempts:
2 left
💡 Hint
The outer loop iterates rows, inner loop iterates columns.
🧠 Conceptual
expert
3:00remaining
Memory layout of multi-dimensional arrays in C#
Which statement best describes how multi-dimensional arrays are stored in memory in C#?
AMulti-dimensional arrays are stored as arrays of arrays (jagged arrays) with separate memory blocks for each sub-array.
BMulti-dimensional arrays are stored as a single contiguous block of memory in row-major order.
CMulti-dimensional arrays are stored in column-major order similar to Fortran arrays.
DMulti-dimensional arrays are stored randomly in memory without any specific order.
Attempts:
2 left
💡 Hint
Think about how C# handles rectangular arrays compared to jagged arrays.