Skip to main content

Practice · 2 of 4

Count the boxes

CHALLENGE
Difficulty: advanced+25 XP

Implement static int Sum(ReadOnlySpan<int> values) that sums a span WITHOUT boxing, and static object BoxSum(ReadOnlySpan<int> values) that returns the sum as object (this one boxes exactly once, at the return). The test verifies both values AND that BoxSum returns a boxed int.

Back to lesson: Practice: Semantics under the microscope