sum numbers 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: sum array c#
//
// Declare two collections of int elements.
//
int[] array1 = { 1, 3, 5, 7 };
List<int> list1 = new List<int>() { 1, 3, 5, 7 };
//
// Use Sum extension on their elements.
int sum1 = array1.Sum();
int sum2 = list1.Sum();