Recall & Review
beginner
What is a single-dimensional array in C#?
A single-dimensional array in C# is a collection of elements of the same type stored in a linear sequence. It is like a row of boxes where each box holds one value.
Click to reveal answer
beginner
How do you declare a single-dimensional array of integers with 5 elements in C#?
You declare it like this: <br>
int[] numbers = new int[5];<br>This creates an array named 'numbers' that can hold 5 integers.Click to reveal answer
beginner
What does the number inside the square brackets mean in
new int[5]?It means the size of the array, or how many elements it can hold. Here, the array can hold 5 integers.
Click to reveal answer
beginner
How can you initialize a single-dimensional array with values at the time of declaration?
You can write: <br>
int[] numbers = {1, 2, 3, 4, 5};<br>This creates an array with 5 elements and sets their values immediately.Click to reveal answer
beginner
What is the index of the first element in a C# array?
The first element's index is 0. Arrays in C# are zero-based, so counting starts from 0.
Click to reveal answer
How do you declare a single-dimensional array of strings named 'names' with 3 elements in C#?
✗ Incorrect
Option A correctly declares a string array with 3 elements. The others have syntax errors.
What is the index of the last element in an array declared as
int[] arr = new int[10];?✗ Incorrect
Since indexing starts at 0, the last element is at index 9 for an array of size 10.
Which of the following initializes an array with values 10, 20, 30 in C#?
✗ Incorrect
Options A and C correctly declare and initialize the array with the given values. The others have syntax errors.
What happens if you try to access an array element with an index outside its range?
✗ Incorrect
Accessing outside the array bounds causes a runtime error in C#.
Which keyword is used to create a new array instance in C#?
✗ Incorrect
The 'new' keyword is used to create new array instances.
Explain how to declare and initialize a single-dimensional array of integers with 4 elements in C#.
Think about the syntax: type[], name, new, size or values.
You got /3 concepts.
Describe what zero-based indexing means in the context of C# arrays.
Imagine counting boxes starting at zero.
You got /3 concepts.