Recall & Review
beginner
What is a jagged array in C#?
A jagged array is an array of arrays, where each inner array can have a different length. It allows storing rows of different sizes, unlike a rectangular (multidimensional) array.
Click to reveal answer
beginner
How do you declare a jagged array of integers with 3 rows in C#?
You declare it like this: <br>
int[][] jaggedArray = new int[3][];<br>This creates an array with 3 elements, each of which can point to an integer array of any length.Click to reveal answer
beginner
How do you initialize the second row of a jagged array to have 4 elements?
You assign a new array to the second row like this:<br>
jaggedArray[1] = new int[4];<br>This sets the second row to hold 4 integers.Click to reveal answer
beginner
How do you access the third element of the first row in a jagged array?
You use two indexes:<br>
jaggedArray[0][2]<br>The first index selects the row, the second index selects the element in that row.Click to reveal answer
intermediate
What is the difference between a jagged array and a multidimensional array in C#?
A jagged array is an array of arrays where each inner array can have different lengths.<br>A multidimensional array is a single block of memory with fixed size in each dimension.<br>Jagged arrays offer more flexibility in row sizes.
Click to reveal answer
How do you declare a jagged array with 5 rows in C#?
✗ Incorrect
Option A correctly declares a jagged array with 5 rows, each row can have different lengths.
Which syntax accesses the 2nd element of the 3rd row in a jagged array named 'jagged'?
✗ Incorrect
Indexes start at 0, so the 3rd row is index 2 and the 2nd element is index 1.
Can jagged arrays have rows of different lengths?
✗ Incorrect
Jagged arrays are designed to allow rows of different lengths.
What happens if you try to access an element in a jagged array row that has not been initialized?
✗ Incorrect
If the inner array is null (not initialized), accessing it causes a NullReferenceException.
Which of these is a correct way to initialize a jagged array with 2 rows, first with 3 elements and second with 2 elements?
✗ Incorrect
Option C correctly declares the jagged array and initializes each row with different lengths.
Explain what a jagged array is and how it differs from a multidimensional array in C#.
Think about rows and their lengths.
You got /4 concepts.
Describe how to declare, initialize, and access elements in a jagged array in C#.
Remember jagged arrays are arrays of arrays.
You got /4 concepts.