Recall & Review
beginner
What is boxing in C#?
Boxing is the process of converting a value type (like int) to an object type, wrapping the value inside a heap-allocated object.
Click to reveal answer
beginner
Why can boxing cause performance issues?
Boxing creates a new object on the heap and copies the value, which uses extra memory and CPU time, and can increase garbage collection pressure.
Click to reveal answer
intermediate
What happens during unboxing?
Unboxing extracts the value type from the boxed object, which requires type checking and copying the value back, adding overhead.
Click to reveal answer
intermediate
How can you avoid boxing in C#?
Use generic types or methods, or work directly with value types instead of casting them to object types.
Click to reveal answer
beginner
What is a real-life analogy for boxing?
Imagine putting a small item (value type) into a box (object) to carry it around. This takes extra effort and space compared to carrying the item directly.
Click to reveal answer
What does boxing do in C#?
✗ Incorrect
Boxing wraps a value type inside an object, converting it to an object type.
Which of these is a performance cost of boxing?
✗ Incorrect
Boxing creates a new object on the heap and copies the value, which costs time and memory.
How can you reduce boxing in your code?
✗ Incorrect
Generics allow working with value types without boxing.
What is unboxing?
✗ Incorrect
Unboxing extracts the original value type from the boxed object.
Which scenario causes boxing?
✗ Incorrect
Assigning a value type like int to an object causes boxing.
Explain what boxing is and why it can affect performance in C#.
Think about how value types become objects.
You got /4 concepts.
Describe two ways to avoid boxing in your C# programs.
Consider how to keep values as value types.
You got /3 concepts.