Practice · 3 of 3
Sum any numeric type
CHALLENGE
Difficulty: advanced+25 XP
Implement static T Sum<T>(T[] values) where T : INumber<T> summing all elements starting from T.Zero, and static T Average<T>(T[] values) where T : INumber<T> returning Sum / count (use T.CreateTruncating for the count). Works for int, double, decimal — one implementation.
Press Submit to check your solution.
Back to lesson: Practice: Generic machinery