Skip to main content

Practice ยท 2 of 3

Boxing Detective

CHALLENGE
Difficulty: intermediate+25 XP

Implement the probes so the tests confirm the real boxing rules: ``csharp /* true iff the two objects are the same box (reference equality) */ static bool SameBox(object a, object b); /* unbox to the EXACT type named by the generic parameter: UnboxAs<int>(boxedInt) works; UnboxAs<double>(boxedInt) must throw InvalidCastException (let it propagate). */ static T UnboxAs<T>(object boxed) where T : struct; /* sum WITHOUT boxing per element: takes int[] and returns long */ static long SumNoBox(int[] values); ``

Back to lesson: Practice: Semantics Gym