Given an array of ints, write a C# method to total all the values that are even numbers.

Technology CommunityCategory: C#Given an array of ints, write a C# method to total all the values that are even numbers.
VietMX Staff asked 3 years ago
static long TotalAllEvenNumbers(int[] intArray) {
  return intArray.Where(i => i % 2 == 0).Sum(i => (long)i);
}

or

static long TotalAllEvenNumbers(int[] intArray) {
  return (from i in intArray where i % 2 == 0 select (long)i).Sum();
}