adding the sum in c# code example
Example 1: sum of digits in c#
int num = 123;
int sum = 0;
while(num > 0)
{
sum += number % 10;
num /= 10;
}
Console.WriteLine(sum); // output: 6
Example 2: c# sum of array elements#
int[] arr = new int[] { 1, 2, 3 };
int sum = 0;
for (int i = 0; i < arr.Length; i++)
{
sum += arr[i];
}
int[] arr = { 3, 6, 4, 1, 6, 8 };
// returns 1
Array.IndexOf(arr, 6);
int maxValue = anArray.Max();
int maxIndex = anArray.ToList().IndexOf(maxValue);