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

Multi-dimensional arrays in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a 2D array of integers with 3 rows and 4 columns.

C Sharp (C#)
int[,] matrix = new int[[1], 4];
Drag options to blanks, or click blank then click option'
A3
B4
C5
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing rows and columns sizes.
Using a single-dimensional array syntax.
2fill in blank
medium

Complete the code to assign the value 10 to the element in the second row and third column of the 2D array.

C Sharp (C#)
matrix[[1], 2] = 10;
Drag options to blanks, or click blank then click option'
A3
B1
C2
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 2 instead of 1 for the second row index.
Confusing row and column indices.
3fill in blank
hard

Fix the error in the code to correctly declare and initialize a 2D array with 2 rows and 3 columns filled with zeros.

C Sharp (C#)
int[,] grid = new int[[1], 3];
Drag options to blanks, or click blank then click option'
A2
B0
C3
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3 instead of 2 for the number of rows.
Using zero or one as the first dimension size.
4fill in blank
hard

Fill both blanks to create a nested loop that prints all elements of a 2D array named 'data'.

C Sharp (C#)
for (int i = 0; i < data.GetLength([1]); i++) {
    for (int j = 0; j < data.GetLength([2]); j++) {
        Console.WriteLine(data[i, j]);
    }
}
Drag options to blanks, or click blank then click option'
A0
B1
C2
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the dimension indices.
Using invalid dimension numbers like 2 or 3.
5fill in blank
hard

Fill all three blanks to create a 2D array 'table' with 2 rows and 3 columns, assign 5 to the first element, and print it.

C Sharp (C#)
int[,] table = new int[[1], [2]];
table[0, 0] = [3];
Console.WriteLine(table[0, 0]);
Drag options to blanks, or click blank then click option'
A3
B5
C2
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping rows and columns in the declaration.
Assigning the wrong value to the first element.