calculate sum of all elements in array, UInt16 implementation

This commit is contained in:
Michael Becker 2021-10-27 07:43:58 -04:00
parent c09ec3549d
commit 71aa88c716
No known key found for this signature in database
GPG Key ID: 98C333A81F18C22C

View File

@ -36,5 +36,20 @@ namespace MBS.Framework
{
return (long)((random.NextDouble() * (maxValue - minValue)) + minValue);
}
/// <summary>
/// Calculates the sum of all elements in the array.
/// </summary>
/// <returns>The sum of all elements in the array.</returns>
/// <param name="array">The array to sum.</param>
public static ushort Sum(this ushort[] array)
{
ushort value = 0;
for (int i = 0; i < array.Length; i++)
{
value += array[i];
}
return value;
}
}
}