Recall & Review
beginner
What does it mean that arrays are reference types in C#?
Arrays store a reference (or address) to the actual data in memory, not the data itself. When you assign one array variable to another, both variables point to the same array in memory.
Click to reveal answer
beginner
What happens if you change an element of an array through one variable when arrays are reference types?
The change is visible through all variables that reference the same array because they all point to the same data in memory.
Click to reveal answer
intermediate
How can you create a copy of an array to avoid reference sharing?
You can create a new array and copy elements manually or use methods like Array.Copy or the Clone method to create a separate copy in memory.
Click to reveal answer
beginner
Consider this code:<br>
int[] a = {1, 2, 3};<br>int[] b = a;<br>b[0] = 10;<br>What is the value of a[0] after this code runs?The value of a[0] is 10 because both a and b reference the same array. Changing b[0] changes the array itself.
Click to reveal answer
intermediate
Why is understanding array reference behavior important in programming?
It helps avoid bugs caused by unintended changes to shared data and allows you to manage memory and data flow correctly.
Click to reveal answer
In C#, what happens when you assign one array variable to another?
✗ Incorrect
Arrays are reference types, so assignment copies the reference, not the data.
If you modify an element of an array through one variable, what happens to other variables referencing the same array?
✗ Incorrect
Since all variables reference the same array, changes are visible through all references.
Which method can you use to create a separate copy of an array in C#?
✗ Incorrect
Array.Copy copies elements to a new array, creating a separate copy.
What is the type of an array in C#?
✗ Incorrect
Arrays are reference types in C#.
Why might unintended sharing of arrays cause bugs?
✗ Incorrect
Unintended sharing means one change affects all references, which can cause unexpected behavior.
Explain how arrays behave as reference types in C# and what happens when you assign one array variable to another.
Think about how memory addresses work for arrays.
You got /4 concepts.
Describe how to create a separate copy of an array to avoid shared reference issues.
Consider methods that duplicate array data.
You got /4 concepts.