Assuming you mean summing together the values of the integers in the list, then you'd just declare an integer variable and increment it by the values of each element:
List<int> numbers = { 1, 2, 3, 4, 5 };
int result = 0;
foreach (int number in numbers)
{
result += number;
}
However you can achieve this even easier using the
Sum()
method:
List<int> numbers = { 1, 2, 3, 4, 5 };
int result = numbers.Sum(number => number);