Unsafe checkpoint
Challenge on lesson: Checkpoint: unsafe and interop
CHALLENGE
Difficulty: advanced+25 XP
Implement static int UnsafeSum(ReadOnlySpan<int> values) that sums an int span using unsafe pointer arithmetic: fixed (int* p = values) (or inside an unsafe method on a span via GetPinnableReference), walk with p[i], accumulate. The test verifies correctness AND that it compiles only because the harness adds -unsafe (the same flag real projects configure). Also implement static byte[] Reinterpret(long value) that reinterprets a long's bytes as a 4-element ushort array copy using Unsafe/MemoryMarshal โ demonstrating reinterpretation without pointers.
Press Submit to check your solution.
Back to lesson: Checkpoint: unsafe and interop