From 71aa88c716d7fee3c4d0b1cef6eb05dcb9ab0403 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Wed, 27 Oct 2021 07:43:58 -0400 Subject: [PATCH] calculate sum of all elements in array, UInt16 implementation --- MBS.Framework/MathExtensions.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/MBS.Framework/MathExtensions.cs b/MBS.Framework/MathExtensions.cs index 1a6a5bc..94d99d7 100644 --- a/MBS.Framework/MathExtensions.cs +++ b/MBS.Framework/MathExtensions.cs @@ -36,5 +36,20 @@ namespace MBS.Framework { return (long)((random.NextDouble() * (maxValue - minValue)) + minValue); } + + /// + /// Calculates the sum of all elements in the array. + /// + /// The sum of all elements in the array. + /// The array to sum. + public static ushort Sum(this ushort[] array) + { + ushort value = 0; + for (int i = 0; i < array.Length; i++) + { + value += array[i]; + } + return value; + } } }