Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardC#boxing and unboxing costSingle-choice MCQ

What is the precise difference in heap activity between calling list.Add(42) on a List<int> versus on a List<object>, and why does the generic version avoid it?

List<int> a = new(); a.Add(42); // no boxing: stored inline in int[] List<object> b = new(); b.Add(42); // boxes 42 onto the heap