---
title: "Create a program to find the sum of all even numbers in an array of integers."  
description: "Create a program to find the sum of all even numbers in an array of integers."  
author: "Utpal Vishwas"  
published: 2023-06-14  
updated: 2023-06-15  
canonical: https://www.mindstick.com/forum/158745/create-a-program-to-find-the-sum-of-all-even-numbers-in-an-array-of-integers  
category: "c#"  
tags: ["c#", "array list", "programs"]  
reading_time: 2 minutes  

---

# Create a program to find the sum of all even numbers in an array of integers.

Create a [program](https://www.mindstick.com/blog/12337/scaling-up-your-mentorship-program) to find the [sum](https://www.mindstick.com/forum/159332/how-can-i-use-sum-in-linq) of all even numbers in an [array of integers](https://www.mindstick.com/forum/157932/write-a-program-to-find-the-missing-number-in-an-array-of-integers).

## Replies

### Reply by Aryan Kumar

Sure, here is a C# program to find the sum of all even numbers in an [array](https://www.mindstick.com/articles/335/jagged-array-in-c-sharp-dot-net) of integers:

C#

```plaintext
using System;

public class SumOfEvenNumbers {

    public static int Sum(int[] array) {

        // Initialize the sum to 0
        int sum = 0;

        // Iterate through the array
        for (int i = 0; i < array.Length; i++) {

            // Check if the current number is even
            if (array[i] % 2 == 0) {

                // Add the current number to the sum
                sum += array[i];
            }
        }

        // Return the sum
        return sum;
    }

    public static void Main() {

        // Create an array of integers
        int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

        // Find the sum of all even numbers in the array
        int sum = Sum(array);

        // Print the sum
        Console.WriteLine("The sum of all even numbers in the array is: " + sum);
    }
}
```

This program will first create an array of integers. It will then call the Sum method to find the sum of all even numbers in the array. The program will then print the sum.

Here is an example of how to run the program:

Code snippet

```plaintext
C#> SumOfEvenNumbers.exe
The sum of all even numbers in the array is: 30
```


---

Original Source: https://www.mindstick.com/forum/158745/create-a-program-to-find-the-sum-of-all-even-numbers-in-an-array-of-integers

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
