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

Multi-dimensional arrays in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a multi-dimensional array in C#?
A multi-dimensional array is an array with more than one dimension, like a table with rows and columns. It stores data in a grid-like structure.
Click to reveal answer
beginner
How do you declare a 2D array of integers with 3 rows and 4 columns in C#?
You declare it like this: <br>int[,] array = new int[3,4];<br>This creates a grid with 3 rows and 4 columns.
Click to reveal answer
beginner
How do you access the element in the 2nd row and 3rd column of a 2D array named array?
Use array[1, 2] because indexing starts at 0. So row 2 is index 1, column 3 is index 2.
Click to reveal answer
intermediate
What is the difference between a rectangular array and a jagged array in C#?
A rectangular array has rows and columns all the same size (like a grid). A jagged array is an array of arrays where each row can have different lengths.
Click to reveal answer
beginner
How can you loop through all elements of a 2D array in C#?
Use two nested loops: one for rows and one for columns. For example:<br>for (int i = 0; i < rows; i++) {<br> for (int j = 0; j < cols; j++) {<br> // access array[i, j]<br> }<br>}
Click to reveal answer
How do you declare a 3D array of doubles with dimensions 2x3x4 in C#?
Adouble arr = new double[2,3,4];
Bdouble[][][] arr = new double[2][3][4];
Cdouble[] arr = new double[2,3,4];
Ddouble[,,] arr = new double[2,3,4];
What is the index of the first element in any dimension of a C# array?
A-1
B1
C0
DDepends on the array
Which of these is a jagged array declaration in C#?
Aint[] jagged = new int[3,4];
Bint[][] jagged = new int[3][];
Cint[,] jagged = new int[3,4,5];
Dint jagged = new int[3][];
How do you find the number of rows in a 2D array named arr?
Aarr.GetLength(0)
Barr.GetLength(1)
Carr.Length
Darr.Rank
What will happen if you try to access array[3,0] in a 3x4 array?
AThrows an IndexOutOfRangeException
BReturns the first element
CReturns null
DReturns default value 0
Explain how to declare, initialize, and access elements in a 2D array in C#.
Think of a table with rows and columns.
You got /4 concepts.
    Describe the difference between rectangular and jagged arrays and when you might use each.
    Imagine a perfect grid vs. uneven shelves.
    You got /4 concepts.