Recall & Review
beginner
What is reference sharing in C#?
Reference sharing happens when two or more variables point to the same object in memory, so changes through one variable affect the others.
Click to reveal answer
beginner
Why can reference sharing cause bugs?
Because modifying an object through one reference changes it for all references, leading to unexpected side effects if not intended.
Click to reveal answer
intermediate
What is a common bug caused by modifying a shared list in C#?
If multiple variables share the same list reference, adding or removing items from one variable changes the list for all, which can cause logic errors.
Click to reveal answer
intermediate
How can you avoid bugs from reference sharing when working with objects?
Create a copy of the object instead of sharing the reference. For example, use cloning or copy constructors to get a new independent object.
Click to reveal answer
advanced
What is a shallow copy vs a deep copy in C#?
A shallow copy duplicates the top-level object but keeps references to nested objects. A deep copy duplicates everything, creating fully independent objects.
Click to reveal answer
What happens if you modify an object through one reference when multiple references share it?
✗ Incorrect
Because all references point to the same object, changes through one reference affect all.
Which of these can help avoid bugs from reference sharing?
✗ Incorrect
Creating copies ensures each variable works with its own object, preventing unintended side effects.
What is a shallow copy in C#?
✗ Incorrect
A shallow copy duplicates the main object but nested objects remain shared.
If two variables share a list reference, what happens when you add an item via one variable?
✗ Incorrect
Both variables point to the same list, so changes are visible through both.
Which method is NOT a way to create a copy of an object in C#?
✗ Incorrect
Assigning one variable to another copies the reference, not the object itself.
Explain what reference sharing is and why it can cause bugs in C# programs.
Think about how variables can point to the same object.
You got /4 concepts.
Describe how to avoid bugs caused by reference sharing when working with objects in C#.
Consider how to make independent objects.
You got /4 concepts.